<div dir="ltr">Solutions like this look reasonable, until you try to use normal control flow statements as you would in other loops. In the closure, a break or continue are illegal, and a return acts like a continue.<div><span class=""><br>var</span><span class=""> ok = </span><span class="">true</span><br></div><div><p class=""><span class="">5</span><span class="">.</span><span class="">times</span><span class=""> {<br></span>    ok = someTest()</p><p class=""><span class="">    </span><span class="">if</span><span class=""> (!</span><span class="">ok</span><span class="">) {<br>        //break - Nope!<br></span><span class="">        </span><span class="">return //Sure, but loop continues anyway<br></span>    }<br>}</p><p class="">Sure, it&#39;s a contrived example, but it&#39;s easy to see how this construct is not like other loops. </p><p class="">On the other hand, it might be nice to be able to decorate a closure such that break and continue behave as one might expect inside a loop, but that sounds like a can of worms.<br><br></p><p class=""><br></p><p class=""><br></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 9, 2015 at 1:05 AM, André Videla <span dir="ltr">&lt;<a href="mailto:zephyz@me.com" target="_blank">zephyz@me.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>How about having a default implementation in the standard library for it? </div><div>We avoid syntactic sugar and we allow for this very simple yet useful expression.</div><div>And we’ve seen solutions in this thread using autoclosurses and extensions</div><div><br></div><div>5.times {</div><div>   …</div><div>}</div><div><br></div><div>or a function</div><div><br></div><div>repeat(4) {</div><div>   …</div><div>}</div><div><br></div><div>all sound good to me.</div><div><br></div><div>- André</div><div><br></div><br><div><blockquote type="cite"><div><div class="h5"><div>On 09 Dec 2015, at 06:58, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div style="word-wrap:break-word"><div><div class="h5">On Dec 8, 2015, at 4:43 PM, Daniel Steinberg via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<div><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">For me this comes up when teaching children or new programmers. (Perhaps not a valid use case)</div></div></blockquote><div><br></div><div>This is a very valid use case.</div><div><br></div><div>FWIW, “repeat N {}” was originally designed and scoped into the Swift 2 implementation of the feature, but was cut due to schedule limitations.  There is precedent for this sort of feature in many teaching oriented languages (e.g. Logo).</div><div><br></div><div>I’d say that the pro’s and con’s of this are:</div><div><br></div><div>+ Makes a simple case very simple, particularly important in teaching.</div><div>+ Even if you aren’t familiar with it, you can tell at first glance what the behavior is.</div><div>- It is “just syntactic sugar”, which makes the language more complex.</div><div>- It is a very narrow feature that is useful in few practical situations.</div><div><br></div><div>-Chris</div></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=41N46VivWCZSszJfIBo5GmyHxjrOakJAcXHty8ZW-2FGhs8teaOUlcVyh8QnI9g7h0iDnLCWCVHmPKUk54l97lzseMpm3DSkV0swNaGZto3zxhnMCqLQO4eo92JbTfmmNB8XrsSs3G-2BE6Bhpo-2FZpKiHAXDZYkMyynnOU2qAQADCwtl8wEB8zy3IqigpG6fQdiX7kYktIL4GEZUVkI-2BmLE0cA-3D-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div><span class="">
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div></blockquote></div><br></div>