<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I think this is easy to implement yourself if you want that.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><div class="gmail_default"><font face="georgia, serif">extension Int {</font></div><div class="gmail_default"><font face="georgia, serif">    func times(@autoclosure closure: ()-&gt;()) {</font></div><div class="gmail_default"><font face="georgia, serif">        for _ in 1 ... self {</font></div><div class="gmail_default"><font face="georgia, serif">            closure()</font></div><div class="gmail_default"><font face="georgia, serif">        }</font></div><div class="gmail_default"><font face="georgia, serif">    }</font></div><div class="gmail_default"><font face="georgia, serif">}</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">let a = 5</font></div><div class="gmail_default"><font face="georgia, serif">5.times(print(&quot;good luck!&quot;))</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">zhaoxin</font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 9, 2016 at 8:52 PM, Cihat Gündüz <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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Just an update to my thoughts about the times method in the meantime:<div><br></div><div>Currently I’m using my <a href="https://github.com/Flinesoft/HandySwift" target="_blank">HandySwift</a> 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>my new proposal</b>:</div><div><br></div><div>`repeat 5 times { /* code */ }`</div><div><br></div><div>Also somebody here asked for <b>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" target="_blank">source</a>):</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">public<span style="color:#000000"> </span>extension<span style="color:#000000"> </span><span style="color:#703daa">Array</span><span style="color:#000000"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:#bb2ca2">public</span> <span style="color:#bb2ca2">var</span> sample: <span style="color:#703daa">Element</span>? {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:#bb2ca2">get</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            <span style="color:#bb2ca2">if</span> <span style="color:#bb2ca2">self</span>.<span style="color:#703daa">count</span> &gt; <span style="color:#272ad8">0</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">                <span style="color:#bb2ca2">let</span> randomIndex = <span style="color:#bb2ca2">self</span>.startIndex.advancedBy(<span style="color:#703daa">Int</span>(randomBelow: <span style="color:#bb2ca2">self</span>.count))</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">                <span style="color:#bb2ca2">return</span> <span style="color:#bb2ca2">self</span>[randomIndex]</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            <span style="color:#bb2ca2">return</span> <span style="color:#bb2ca2">nil</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">    <br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:#bb2ca2">public</span> <span style="color:#bb2ca2">func</span> sample(size size: <span style="color:#703daa">Int</span>) -&gt; [<span style="color:#703daa">Element</span>]? {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:#bb2ca2">if</span> <span style="color:#bb2ca2">self</span>.<span style="color:#703daa">count</span> &gt; <span style="color:#272ad8">0</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            <span style="color:#bb2ca2">var</span> sampleElements: [<span style="color:#703daa">Element</span>] = []</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            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">                sampleElements.append(<span style="color:#bb2ca2">self</span>.sample!)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            <span style="color:#bb2ca2">return</span> sampleElements</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:#bb2ca2">return</span> <span style="color:#bb2ca2">nil</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div></div><div><br><div><blockquote type="cite"><div>Am 21.12.2015 um 17:00 schrieb Stephen Celis via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:</div><br><div><div style="word-wrap:break-word"><div>Just another -1. While I appreciated it in Ruby, I don&#39;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&#39;s did—then maybe (I&#39;d prefer the former and hold off on the latter, though).</div><div><br></div><div>In the meantime, &quot;repeat 5 { /* do something */ }&quot; seems better to me.</div><div><br></div><div>Stephen</div><br><div><blockquote type="cite"><div>On Dec 20, 2015, at 9:32 PM, T.J. Usiyan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr">-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><div class="gmail_quote">On Sun, Dec 20, 2015 at 9:10 PM, Howard Lovatt 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">+1 to 5.times{stuff} from me. I much prefer library functions to language extensions.<br clear="all"><div><br></div><div>  -- Howard.<br></div>
</div>
<img 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">
<br>_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
<img 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">
_______________________________________________<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></div></blockquote></div><br>
<img 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>
_______________________________________________<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></div></blockquote></div><br></div>
<img 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>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><br>Owen Zhao<br></div></div></div>
</div>