<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=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra">An obvious question is, should it be equivalent to 1...n, or 0..&lt;n?</div></div></blockquote><br class=""></div><div class="">I think that’s exactly why this isn’t a good idea. The semantics of `for i in 5` are not immediately clear at all.</div><div class=""><br class=""></div><div class="">If this was to be a language feature, `repeat 5`, suggested by Chris, seems like the least-ambiguous choice.</div><br class=""><div class="">
<div class="">— Radek</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 22:09, Jacob Bandes-Storch 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=""><div class="gmail_extra">This can be done pretty easily, although I think the approach has the potential to cause confusion elsewhere in code. An obvious question is, should it be equivalent to 1...n, or 0..&lt;n?</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_extra">extension Int: SequenceType {</div><div class="gmail_extra">&nbsp; &nbsp; public func generate() -&gt; RangeGenerator&lt;Int&gt; {</div><div class="gmail_extra">&nbsp; &nbsp; &nbsp; &nbsp; return (0..&lt;self).generate()</div><div class="gmail_extra">&nbsp; &nbsp; }</div><div class="gmail_extra">}</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">for i in 5 {</div><div class="gmail_extra">&nbsp; &nbsp; print("hello \(i)")</div><div class="gmail_extra">}</div></div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class="">Jacob Bandes-Storch<br class=""></div></div></div></div>
<br class=""><div class="gmail_quote">On Fri, Dec 18, 2015 at 1:03 PM, Brent Royal-Gordon 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">&gt; I’d like to propose an addition of a useful method, especially for beginners that also makes Swift much more readable in some situations: The addition of a .times method to Integer type(s).<br class="">
<br class="">
</span>I’ve said it before, but I don’t think `times` is a good solution for learners. It teaches them a form of looping they will never use in practice and does not allow them to practice with ancillary loop skills like `break` and `continue`.<br class="">
<br class="">
I think our best bet is to extend the `for` loop to allow a single number, meaning either `1…n` or `0..&lt;n` (you can argue it either way), and also to allow the `variableName in` part to be omitted, meaning `_ in`. This gives us the pedagogical simplicity of a “do this N times” loop, but couches it in a form where, when the student moves on, more commonly used loop forms are a straightforward extension of that simple case.<br class="">
<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; for 5 { print(“Hello!”) }<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; for i in 5 { print(“Hello \(i)!”) }<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; for i in 10..&lt;20 { print(“Hello \(i)!”) }<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; for i in 10...20 { print(“Hello \(i)!”) }<br class="">
<span class=""><font color="#888888" class=""><br class="">
--<br class="">
Brent Royal-Gordon<br class="">
Architechies<br class="">
</font></span><div class=""><div class="h5"><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="">
</div></div></blockquote></div><br class=""></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=4hhvaxvZNsLrnZM9llg93kxoqfFYC8lhv8HAehOIDqLrRLXLvM2LNPW6bue1Bps4Vo1Wdz-2F9beNvMflXYUCh0lQ-2F7ChHyqU-2BvD38r-2BZJU1P1vQAgzDlFdGQo1S-2FPS8Wy-2F9L7To9LhJN81U0m7sP6u3V0q2JE7YG-2FimpmwA3T9uH8vPglAAc8EZYt32ohw2BfK-2B6nBw9xK0Ra1MjP5zBH-2BMnzBpWnxwUOoMYeEwMVB9Y-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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>