<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You may want to take a peek here: <a href="https://gist.github.com/erica/a51a981ee0352235204692affa959307" class="">https://gist.github.com/erica/a51a981ee0352235204692affa959307</a><div class=""><br class=""></div><div class="">-- E<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 13, 2016, at 8:52 AM, Hans Huck via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div style="font-family: Verdana;font-size: 12.0px;" class=""><div class="">
<div class="">Rationale:</div>
<div class=""> </div>
<div class="">Swift's For-In-loop is fine, as long as you don't need an iteration step size other than 1/-1, in which case it becomes unexpectedly inconsistent and unwieldy.</div>
<div class=""> </div>
<div class="">for i in 1...10<br class="">
for i in reverse(10...1)<br class="">
for i in stride(from:1, through:10, by:3)<br class="">
or even<br class="">
for i in 1.stride(through:10, by:3)</div>
<div class=""> </div>
<div class="">The above sequence is not only confusing for teaching purposes/beginners (first lesson: protocols. really?), but also unnecessarily bulky for everyday use. It's a For-loop, one of the most basic and frequently used structures in any language -- please let's make it pithy.</div>
<div class=""> </div>
<div class=""><br class="">
Comparison:</div>
<div class=""> </div>
<div class="">Currently, even the C-style For-loop we are just about to get rid of could be argued to be more concise and consistent, but significantly more so are the likes of</div>
<div class=""> </div>
<div class=""># Python<br class="">
for i in range(1, 10, 3):</div>
<div class=""> </div>
<div class="">-- Lua<br class="">
for i = 1, 10, 3</div>
<div class=""> </div>
<div class="">' Basic<br class="">
for i = 1 to 10 step 3</div>
<div class=""> </div>
<div class="">(* Modula-2 *)<br class="">
for i := 1 to 10 by 3</div>
<div class=""> </div>
<div class="">// Chapel<br class="">
for i in 1..10 by 3</div>
<div class=""> </div>
<div class="">or any other remotely relevant non-C-style language that allows For-loops with an altered step size.</div>
<div class=""> </div>
<div class="">While there are other issues like having to use reverse(1...10) instead of simply 10...1, (which compiles, but doesn't run, even when using literals -- why?) none of it goes against the grain as much as being forced to type out stride(boiboiboilerplate) for a simple iteration.</div>
<div class=""> </div>
<div class=""><br class="">
Suggestion(s):</div>
<div class=""> </div>
<div class="">A) Add keyword "by" as syntactic sugar, used as in Modula/Chapel (and tip our hat to Algol 68):</div>
<div class=""> </div>
<div class="">// Swift<br class="">
for i in 1...10 by 3<br class="">
for i in reverse(1...10) by -3</div>
<div class=""> </div>
<div class="">or even better yet (if feasible):</div>
<div class=""> </div>
<div class="">B)</div>
<div class="">for i in 1...10 by 3<br class="">
for i in 10...1 by -3</div>
<div class=""><br class="">
Please comment, and thanks everyone for reading.</div>
<div class=""> </div>
<div class="">-- Hans</div>
<div class=""> </div>
</div></div></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></body></html>