<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="">I still would like to see this new for-loop statement be implemented in the next Swift version<div class=""><br class=""></div><div class="">&nbsp;Examples:</div><div class="">&nbsp; &nbsp; &nbsp;for v from 0.5 to 30.0 by 0.3 &nbsp; &nbsp;// floating point types</div><div class="">&nbsp; &nbsp; &nbsp;for v from 0 to 100 by 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Integer</div><div class="">&nbsp; &nbsp; &nbsp;for v from 12.0 to -10.0 by -2 &nbsp;// Floating points backward&nbsp;</div><div class=""><br class=""></div><div class="">the “by …” clause is optional for Ints only&nbsp;</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">As previously written, a tolerance factor could also be implemented as optional,</div><div class="">allowing to “end on a humanly accepted boundary” so like in this example</div><div class="">the highest loop value would be 10.0 (+/- ca. 0.000000001) , not 9.9 : &nbsp;</div><div class="">&nbsp;&nbsp;</div><div class="">&nbsp;for v from 0.0 to 10.0 by 0.1 tolerance 0.001 &nbsp; &nbsp;&nbsp;</div><div class=""><br class=""></div><div class="">// the “tolerance ..” clause is optional and allowed for floating point vars only</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Again I need to emphasize very strongly that this for-loop really&nbsp;</div><div class="">has absolutely&nbsp;</div><div class="">&nbsp; &nbsp; &nbsp;nothing, nada, zilch, niente, nichts, niets, niks, rien, zero, nenio,</div><div class="">to do with the:&nbsp;</div><div class=""><br class=""></div><div class="">for i in stride(….&nbsp;</div><div class=""><br class=""></div><div class="">or any other for in… variant working with collections.</div><div class=""><br class=""></div><div class="">However inexplicably, in the previous discussions, a lot of people ***</div><div class="">tried desperately to replace this simple but precious gem,&nbsp;</div><div class="">a miracle of astonishing beauty: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (sorry, got carried away a bit :o)&nbsp;</div><div class="">&nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; for v from v1 to v2 by vstep&nbsp;</div><div class="">&nbsp;</div><div class="">with the collection based&nbsp;</div><div class=""><br class=""></div><div class="">for in ….</div><div class=""><br class=""></div><div class="">The for in… is wonderful for collection based iterations, I use it&nbsp;</div><div class="">all the time like</div><div class="">&nbsp; &nbsp; for thing in things // etc.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">for</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;d&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">in</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">10.0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">stride</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(to:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">5.0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, by: -</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0.1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class="">{</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(d)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 14px;" class="">but, once again -&nbsp;</div><div style="font-family: Helvetica; font-size: 14px;" class="">provided you don’t want to do other operations</div><div style="font-family: Helvetica; font-size: 14px;" class="">on the generated collection before iterating - &nbsp;</div><div style="font-family: Helvetica; font-size: 14px;" class="">a collection is used here totally unnecessary,&nbsp;</div><div style="font-family: Helvetica; font-size: 14px;" class="">which puts a burden on performance because the contents&nbsp;</div><div style="font-family: Helvetica; font-size: 14px;" class="">of a collection are unpredictable&nbsp;</div><div style="font-family: Helvetica; font-size: 14px;" class="">It is also tedious to write and (as a matter of my personal taste) downright ugly.</div><div style="font-family: Helvetica; font-size: 14px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px;" class="">Imho this looks a whole lot better and can also be very efficiently compiled:&nbsp;</div><div class=""><br class=""></div></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 14px;" class=""><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">for</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;d&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">from</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">10.0&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">to </span><span style="color: rgb(39, 42, 216);" class="">5.0 </span><span style="color: rgb(187, 44, 162);" class="">by </span><span style="color: rgb(39, 42, 216);" class="">-0.1</span><span style="color: rgb(187, 44, 162);" class="">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">tolerance&nbsp;</span><span style="color: rgb(39, 42, 216);" class="">0.01</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class="">{</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(d)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><br class=""></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div></div></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 14px;" class="">&nbsp; **************************** !!! **************************************</div><div style="font-family: Helvetica; font-size: 14px;" class="">&nbsp; Important is to see that this “for…” &nbsp;is in fact</div><div style="font-family: Helvetica; font-size: 14px;" class="">&nbsp; a convenience solution for &nbsp;“while” and “repeat” constructs:&nbsp;</div><div style="font-family: Helvetica; font-size: 14px;" class="">&nbsp; and thus a totally different beast compared to the &nbsp; "for in…” !&nbsp;</div><div style="font-family: Helvetica; font-size: 14px;" class="">&nbsp; *********************************************************************</div><div style="font-family: Helvetica; font-size: 14px;" class=""><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> d = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10.0 &nbsp;&nbsp;</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> v = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.0</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> step = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.1</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo; min-height: 19px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">while</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">d</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> &gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5.0 &nbsp; &nbsp;&nbsp;</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{&nbsp;</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">d</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">d</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -= </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">step</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">The above is a bare minimum “while” equivalent</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">for the</span>&nbsp;above for-loop, but still tedious to write!</div><div class=""><br class=""></div><div class="">What more can I write to convince?&nbsp;</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">*** Please tell me if I am wrong, but:&nbsp;</div><div class=""><div class="">I am inclined to think that Functional Programming Minded</div><div class="">Colleagues are trying to push persistently their&nbsp;</div><div class="">(mathematically correct?) &nbsp;way of thinking upon Swift,&nbsp;</div><div class="">thereby ignoring that Swift is and should remain a&nbsp;</div><div class="">general purpose programming language.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">TedvG</div><div class=""><a href="http://www.ravelnotes.com" class="">www.ravelnotes.com</a></div><div class=""><br class=""></div></div><div class="">@Erica,</div><div class=""><br class=""></div><div class="">Erica, as I seem to remember, You wrote somewhere</div><div class="">that Stride is broken, but the "10.0.stride…” example</div><div class="">above works perfectly well in Swift 2.2. playground.</div><div class=""><br class=""></div><div class="">So, what do you regard as wrong with it?</div><div class="">(apart from in some cases needing to specify an&nbsp;</div><div class="">epsilon(tolerance) value? )&nbsp;</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">&nbsp;&nbsp;</div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div style="font-family: Helvetica; font-size: 14px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px;" class=""><br class=""></div><div class=""><br class=""></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><ul class="code-outline-lines" style="border: 0px; font-size: 14.166666030883789px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; list-style-type: none; font-family: Helvetica, Arial, sans-serif;"><li style="border: 0px; font-size: 14.166666030883789px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;" class=""><pre class="code-voice" style="border: 0px; font-size: 0.85em; margin-top: 0px; margin-bottom: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre-wrap; font-family: Menlo, monospace; word-wrap: break-word;"><br class=""></pre></li></ul><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>