<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=""><div class="">I’m +1. It’s not something that’s super common, but `100.times { … }` expresses the intention far better than the rather cryptic `for _ in 0..&lt;100 { … }`.</div><div class=""><br class=""></div><div class="">The only possible concern — and this has been expressed in the proposal to remove `forEach` — is that closures have different semantics than `for`. Mostly, if someone wants to return from a containing function, you can’t do that from a closure.</div><br class=""><div class="">
<div class="">— Radek</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 19:38, Cihat Gündüz 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=""><span 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; float: none; display: inline !important;" class="">I agree with both of you about the alternative implementations.</span><div class="" 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;"><br class=""></div><div class="" 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;">That’s exactly what I’d love to see integrated to the standard library like Ruby is here:<div class=""><a href="http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times" class="">http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times</a></div><div class=""><br class=""></div><div class="">My main problem is that it neither looks<span class="Apple-converted-space">&nbsp;</span><b class="">clean</b><span class="Apple-converted-space">&nbsp;</span>nor<span class="Apple-converted-space">&nbsp;</span><b class="">readable</b><span class="Apple-converted-space">&nbsp;</span>especially for beginners that there is an<span class="Apple-converted-space">&nbsp;</span><i class="">underscore</i><span class="Apple-converted-space">&nbsp;</span>in the closure. Also beginners often get confused with the number of times some code is run when<span class="Apple-converted-space">&nbsp;</span><i class="">starting to count from 0</i><span class="Apple-converted-space">&nbsp;</span>which is also why I think it shouldn’t appear. The .times method would solve both of these problems.</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 18.12.2015 um 19:33 schrieb Etan Kissling &lt;<a href="mailto:kissling@oberon.ch" class="">kissling@oberon.ch</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">(or with a for in loop &nbsp;-- but i guess you have a reason for using .foreach)<div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">for</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">in</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">0</span>..&lt;<span class="" style="color: rgb(39, 42, 216);">5_000</span><span class="Apple-converted-space">&nbsp;</span>{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(61, 29, 129);">print</span>(<span class="" style="color: rgb(209, 47, 27);">"asdf"</span>)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 19:31, Etan Kissling 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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">You don't need stride for this.</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>foo() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; (<span class="" style="color: rgb(39, 42, 216);">0</span>..&lt;<span class="" style="color: rgb(39, 42, 216);">5_000</span>).<span class="" style="color: rgb(61, 29, 129);">forEach</span><span class="Apple-converted-space">&nbsp;</span>{<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">in</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(61, 29, 129);">print</span>(<span class="" style="color: rgb(209, 47, 27);">"asdf"</span>)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; }</div></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 19:25, Cihat Gündüz 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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Dear Swift-Community,<div class=""><br class=""></div><div class="">I’d like to propose an<span class="Apple-converted-space">&nbsp;</span><b class="">addition of a useful method</b>, especially for beginners that also makes Swift much more readable in some situations: The addition of a .times method to Integer type(s).</div><div class=""><br class=""></div><div class="">For example recently in one of my projects I wanted to test the scalability of an important piece of code and wrote this method:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>testPerfQualityInPercentWithoutQualityImprovements() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);"><span class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="color: rgb(187, 44, 162);">self</span><span class="">.</span>measureBlock<span class=""><span class="Apple-converted-space">&nbsp;</span>{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">let</span><span class="Apple-converted-space">&nbsp;</span>expectedQuality =<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">33.33</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">0</span>.<span class="" style="color: rgb(61, 29, 129);">stride</span>(to:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">5_000</span>, by:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">1</span>).<span class="" style="color: rgb(61, 29, 129);">forEach&nbsp;</span>{<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">in</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(49, 89, 93);">XCTAssertEqualWithAccuracy</span>(<span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">crossword</span>.<span class="" style="color: rgb(79, 129, 135);">qualityInPercent</span>, expectedQuality, accuracy:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">0.1</span>) &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; }</div></div><div class=""><br class=""></div><div class="">As you can see what I basically wanted was to repeat the test some thousand times. I also like to use the Ruby language and one thing I love about it is that it has some really handy methods integrated to the language in situations like this which make the code very readable and therefore fun to use.</div><div class=""><br class=""></div><div class="">I’m an even bigger fan of Swift so I’d love to see such useful methods appear in Swift, too and this is the first I came across that I really missed. So I’m asking myself, what if I could write the same code above like this:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">func</span>&nbsp;testPerfQualityInPercentWithoutQualityImprovements() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);"><span class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">self</span><span class="">.</span>measureBlock<span class="">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;expectedQuality =&nbsp;<span class="" style="color: rgb(39, 42, 216);">33.33</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(39, 42, 216);">5_000.times {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(49, 89, 93);">XCTAssertEqualWithAccuracy</span>(<span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">crossword</span>.<span class="" style="color: rgb(79, 129, 135);">qualityInPercent</span>, expectedQuality, accuracy:&nbsp;<span class="" style="color: rgb(39, 42, 216);">0.1</span>) &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; }</div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;">I think it could be added to the Swift standard library very easily (for example by using the .stride method like I used) without any side effects and has enough advantages to be part of Swift itself. What do you think?</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;">I wish you all the best,</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;">Cihat</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;">P.S.: This is my very first mail in such a mailing list so I did everything correctly. ^.^</div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rv24uhtvYv57b57RThnoUBESAxxMDy12HfxuT9sf9VVp3u-2BljgFoOV9Ju-2BtFhXXJ1d8nr-2FYw-2FUNbKUk26rHfCj9zunav26wrq76QmN2VjrXsxpGqGynDLjQOq3xzG0kPrAlahxwYVVKYxWr-2FixGS8o60s13y8Z-2BEl3Y7elh5Tr-2F9t3iW87Nn3MFjpz-2FOHvhx30-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></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=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rudyoy59P95VIFCXE8vsNIm3CRv2xeSfRQi24G3J7csJAwXsAU0KgdqyUmTpkPgjbX8d25r2mfuva9tzq-2FUDdol4HlpIh-2BHPdrv3VJ3o4xk2ghsZ6aTSUz-2FXhHLeKnEcHzsL3XLw-2F2NTNaky7syxtgWh87TGLUN5goHMjwNXVFxk5QMxUtPLGjvJKyN7d4juEc-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></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=""></div></div></div></blockquote></div><br class=""></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=4hhvaxvZNsLrnZM9llg93kxoqfFYC8lhv8HAehOIDqKvItVsoz5WwHw7trsbaMSBtpDjs9JjfnJqcKq5t0nbWDwhSeYLfUL-2Ba6hEMakwJD0BCiQqlDT4OWNOc9cHTwqr9qfjC8eHotAmigv88cXN8rU0DLVMfbxhDntz5QXbuXtYI2JEjUJyb1jqhxk4XNkxN2r4sdpKloVS1JWLgw-2B-2BdFKk0-2BTDVaymxAM2ZEkcoZU-3D" alt="" width="1" height="1" border="0" 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; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span 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; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span></span><span 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; float: none; display: inline !important;" class="">_______________________________________________</span><br 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=""><span 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; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br 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=""><a href="mailto:swift-evolution@swift.org" 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="">swift-evolution@swift.org</a><br 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>