<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’m still of the belief that all types of loops could be condensed down to a single type of loop, the repeat-for loop<div class=""><br class=""></div><div class="">Consider:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The for-in loop:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">repeat<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>for<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> x </span>in<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">..&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(0, 132, 0);" class="">// code</span></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">The C style for loop and the while loop:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">repeat</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> i = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">while</span> someCondition(i) {</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(0, 132, 0);" class="">// code</span></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}&nbsp;</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The repeat while:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">repeat<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>for<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>var<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> i = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(0, 132, 0);" class="">// code</span></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">} </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">while</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> someConditionEvaluatedAfterFirstLoop() </span>// The i variable would likely have to be considered in scope in the while expression</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The currently discussed repeat loop</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">repeat<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(0, 132, 0);" class="">// code</span></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">All follow a very basic pattern: The repeat keyword followed by a for declaration of loop scoped variables, then either a condition in the case of while or an iterator in the case of for-in. Optionally the language could include an “always” keyword that would specify a set of statements that were guaranteed to execute after each run of the loop. For example:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">repeat<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>for<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>var<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> i = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>while<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> i &lt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">} always i += <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class=""><br class=""></span></div><div class="">If this were the case then all current loop constructs and their features could be subsumed by a single type of loop (including the to-be-removed C style for). This does have the problem of increasing the length of some current loop constructs though, specifically for-in.</div><div class=""><br class=""></div><div class="">Tyler</div><div class=""><div class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 10:05 PM, André Videla via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">How about having a default implementation in the standard library for it?&nbsp;</div><div class="">We avoid syntactic sugar and we allow for this very simple yet useful expression.</div><div class="">And we’ve seen solutions in this thread using autoclosurses and extensions</div><div class=""><br class=""></div><div class="">5.times {</div><div class="">&nbsp; &nbsp;…</div><div class="">}</div><div class=""><br class=""></div><div class="">or a function</div><div class=""><br class=""></div><div class="">repeat(4) {</div><div class="">&nbsp; &nbsp;…</div><div class="">}</div><div class=""><br class=""></div><div class="">all sound good to me.</div><div class=""><br class=""></div><div class="">- André</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 09 Dec 2015, at 06:58, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Dec 8, 2015, at 4:43 PM, Daniel Steinberg via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<div class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">For me this comes up when teaching children or new programmers. (Perhaps not a valid use case)</div></div></blockquote><div class=""><br class=""></div><div class="">This is a very valid use case.</div><div class=""><br class=""></div><div class="">FWIW, “repeat N {}” was originally designed and scoped into the Swift 2 implementation of the feature, but was cut due to schedule limitations. &nbsp;There is precedent for this sort of feature in many teaching oriented languages (e.g. Logo).</div><div class=""><br class=""></div><div class="">I’d say that the pro’s and con’s of this are:</div><div class=""><br class=""></div><div class="">+ Makes a simple case very simple, particularly important in teaching.</div><div class="">+ Even if you aren’t familiar with it, you can tell at first glance what the behavior is.</div><div class="">- It is “just syntactic sugar”, which makes the language more complex.</div><div class="">- It is a very narrow feature that is useful in few practical situations.</div><div class=""><br class=""></div><div class="">-Chris</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="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;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=DOmV4Qxg-2B1XOnX4CfTyH3sCllXs7myBcgXMCpdkqNW1zhhmu5CjhfG-2BP2cjImP8nbF1kxPNzJeSqU-2FN8MEq05R9af7oiQFjalFbSVz-2FM-2FkEhvIrTmq3QcHxHgbzAgfXOAhB4Bb-2Ffjvwkzz2q5H1w7z-2BPIOeIZ1JH2Yl-2FMTVmvoMcxhVvu8prN9FoT6ay4U8Lqe4NkrkrLCUZMyOakSyBdFAa578gBycVgeAnNXAvwRI-3D" alt="" width="1" height="1" border="0" style="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;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>