打破Python for循环

时间:2017-08-18 10:24:52

标签: python function loops for-loop break

我想知道是否有一种方法可以让我的for循环在第5次循环之后打印出语句而不是调用它6次并使用我的if语句停止在5。

有没有更有效的方法来实现这一目标?感谢。

let str = '--3c8a15bdc66e76b5 Content-Type: text/plain X-Primitive: integer 8487823278258687528 --3c8a15bdc66e76b5-- --3c8a15bdc66e76b5 Content-Type: text/plain X-Primitive: integer 14918370877051183774 --3c8a15bdc66e76b5-- .'

console.log(str.match(/\b\d+\b/g));

1 个答案:

答案 0 :(得分:3)

您可以迭代到5而不是6并将消息打印出循环:

<div class="mTable">
  <div class="mTableRow">
    <div class="mTableHead">ID</div>
    <div class="mTableHead">Név</div>
    <div class="mTableHead">Komment</div>
    <div class="mTableHead">Tól</div>
    <div class="mTableHead">Ig</div>
    <div class="mTableHead">Missing</div>
  </div>
  <div class="mTableRow">
    <div class="mTableCell">9</div>
    <div class="mTableCell">Robi1 </div>
    <div class="mTableCell"> </div>
    <div class="mTableCell">null</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell"><button class="w3-button w3-round-xxlarge w3-aqua">Választom</button></div>
  </div>
  <div class="mTableRow">
    <div class="mTableCell">31</div>
    <div class="mTableCell">FŰTÉS </div>
    <div class="mTableCell">Hőszivattyú teremhőmérsékletek</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell"><button class="w3-button w3-round-xxlarge w3-aqua">Választom</button></div>
  </div>
  <div class="mTableRow">
    <div class="mTableCell">36</div>
    <div class="mTableCell">Növényház</div>
    <div class="mTableCell">Sablon komment</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell"><button class="w3-button w3-round-xxlarge w3-aqua">Választom</button></div>
  </div>
  <div class="mTableRow">
    <div class="mTableCell">93</div>
    <div class="mTableCell">Üvegház</div>
    <div class="mTableCell">Sablon komment</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell"><button class="w3-button w3-round-xxlarge w3-aqua">Választom</button></div>
  </div>
  <div class="mTableRow">
    <div class="mTableCell">94</div>
    <div class="mTableCell">Cserepes fűtés-hűtés</div>
    <div class="mTableCell">2017 február 9.-i állapott</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell"><button class="w3-button w3-round-xxlarge w3-aqua">Választom</button></div>
  </div>
  <div class="mTableRow">
    <div class="mTableCell">95</div>
    <div class="mTableCell">Cserepes 2017</div>
    <div class="mTableCell">Sablon komment</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell"><button class="w3-button w3-round-xxlarge w3-aqua">Választom</button></div>
  </div>
  <div class="mTableRow">
    <div class="mTableCell">96</div>
    <div class="mTableCell">3 fő helyiség</div>
    <div class="mTableCell">Sablon komment</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell">null</div>
    <div class="mTableCell"><button class="w3-button w3-round-xxlarge w3-aqua">Választom</button></div>
  </div>
</div>
</div>
</div>
</div>