<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 8, 2015 at 4:54 PM, Jason Pollack via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>I propose the following:</div><div><br></div><div>repeat count {</div><div>    //Do something here</div><div>}</div><div><br></div><div>It&#39;s cleaner, and IMO clearer what this code is intended to do.</div></div></blockquote><div><br></div><div>I&#39;m not sure I like the idea of adding this functionality over &quot;repeat&quot;. If &quot;for _ in&quot; is ugly, there&#39;s always the opportunity to add a helper, e.g.:</div><div><br></div><div>    extension Int {</div><div>        func times(@autoclosure while condition: () -&gt; Bool = true, body: () -&gt; Void) {</div><div>            // ...</div><div>        }</div><div>    }</div><div><br></div><div>    5.times {</div><div>        // ...</div><div>    }</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>var ok = true</div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>repeat numberOfTimes {</div><div>    //Do something, possibly set ok to false</div><div>} while ok</div><div><br></div><div>This would repeat the loop a maximum of  &#39;numberOfTimes&#39;, but could be ended early if some signal &#39;ok&#39; is set to false (or, of course, by a break statement).</div></div></blockquote><div><br></div><div>You can use a &quot;where&quot; clause to handle this in a for-in loop:</div><div><br></div><div>    var ok = true</div><div>    for _ in 0..&lt;numberOfTimes where ok {</div><div>        // ...</div><div>    }</div><div><br></div><div>Stephen</div></div></div></div>