<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="">Just an update to my thoughts about the times method in the meantime:<div class=""><br class=""></div><div class="">Currently I’m using my&nbsp;<a href="https://github.com/Flinesoft/HandySwift" class="">HandySwift</a>&nbsp;framework to include a `.times` method for my own usage and I’m happy that way for now – although that solution doesn’t allow for control flow statements. I still think it is a useful feature to be added to the language but I also agree with Chris that `repeat` should be in the name somewhere, so speaking about the syntax the following would be <b class="">my new proposal</b>:</div><div class=""><br class=""></div><div class="">`repeat 5 times { /* code */ }`</div><div class=""><br class=""></div><div class="">Also somebody here asked for <b class="">use cases</b> and here’s one from the HandySwift framework where I implemented it itself (<a href="https://github.com/Flinesoft/HandySwift/blob/develop/Sources/Extensions/ArrayExtension.swift" class="">source</a>):</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="">public<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>extension<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Array</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> sample: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>? {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">get</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">count</span> &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> randomIndex = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.startIndex.advancedBy(<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>(randomBelow: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.count))</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>[randomIndex]</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</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="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> sample(size size: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>) -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>]? {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">count</span> &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> sampleElements: [<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>] = []</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size.times { // &lt;== &lt;== &lt;== &lt;== &lt;== times method used here &lt;== &lt;== &lt;== &lt;== &lt;==</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sampleElements.append(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.sample!)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> sampleElements</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 21.12.2015 um 17:00 schrieb Stephen Celis via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</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="">Just another -1. While I appreciated it in Ruby, I don't think it belongs in the Swift standard library at this time. If closures could be annotated as break/continue-able, and if the standard library started grew a lot—as Ruby's did—then maybe (I'd prefer the former and hold off on the latter, though).</div><div class=""><br class=""></div><div class="">In the meantime, "repeat 5 { /* do something */ }" seems better to me.</div><div class=""><br class=""></div><div class="">Stephen</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 20, 2015, at 9:32 PM, T.J. Usiyan 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=""><div dir="ltr" class="">-1 from me. It is simple enough for an extension and provides little benefit as a standard library inclusion.</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Dec 20, 2015 at 9:10 PM, Howard Lovatt via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">+1 to 5.times{stuff} from me. I much prefer library functions to language extensions.<br clear="all" class=""><div class=""><br class=""></div><div class="">&nbsp; -- Howard.<br class=""></div>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=3FGfocPbgxkNkmje7djckg9Iw-2BGYY3X6RxJ1tkUXKCqmg65k6m3WyZopTCwWnJqytBBL-2FFrB2iaH7LTey4D9-2BVok8gB6pkwWUbJ34wbQzVNsGkzIshicBInnQHKHf3B-2FPnt82GiqB84e2-2FdaprmfsRb0qQIJtsH1Ns-2BMU2OrbHci-2BF2EKWG1VsCNqVpriZ4iPvX02Z9veattDop4VLn3ExKHlfwgJYS4DLLMU0Wx8h8-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" class="">
<br class="">_______________________________________________<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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=5xu02FVv-2BCbxTLHpBsC0RVeXVC5uCln3pUIIeLTlIi2FTGkhQSEBQ7H24l1e6tdSKD2-2F8JQAp27YVSgIAnyeBb5ZrP-2BFinlELeoG-2BCfUpUZA9oaPIIJ1AFR9a22uYWVPx2WxiHDSLmAvjQuLxj-2F5Alkhaw4iJU7WSZHn3hDJ0YaiLvF7WURG0HJchJnCbMTvvrmUJaGH0oyNSelStaUlg11iY0rXljWGniakPYOYJfY-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="">
_______________________________________________<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=aT-2FLnFEhPSFDSL7Gmx0xJo5o6hMhPoYO5Zn1SY30wfe3jE7sTdjZJPzgjej0TW2BGXz8M-2Fh8XSeACa-2BzvK9U5Uc-2BC75olPFvxzLPVypZaVfJSQfX63f2ejAyG7q8fjRvXHBqm2sqOW4JzbmpKt8qXEFd3FiyY0RqGFKM2QcFlDTWcPaWBzMTAFIDyWdzJ7a1OqAiHOBfoxP2S06QO6-2BqiYgOQ3bb1L4HQNjsR4M8xXA-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></body></html>