<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=""> Examples:</div><div class=""> for v from 0.5 to 30.0 by 0.3 // floating point types</div><div class=""> for v from 0 to 100 by 5 // Integer</div><div class=""> for v from 12.0 to -10.0 by -2 // Floating points backward </div><div class=""><br class=""></div><div class="">the “by …” clause is optional for Ints only </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 : </div><div class=""> </div><div class=""> for v from 0.0 to 10.0 by 0.1 tolerance 0.001 </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 </div><div class="">has absolutely </div><div class=""> nothing, nada, zilch, niente, nichts, niets, niks, rien, zero, nenio,</div><div class="">to do with the: </div><div class=""><br class=""></div><div class="">for i in stride(…. </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, </div><div class="">a miracle of astonishing beauty: (sorry, got carried away a bit :o) </div><div class=""> </div><div class=""> for v from v1 to v2 by vstep </div><div class=""> </div><div class="">with the collection based </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 </div><div class="">all the time like</div><div class=""> 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=""> d </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=""> </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: </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=""> </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 - </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 - </div><div style="font-family: Helvetica; font-size: 14px;" class="">a collection is used here totally unnecessary, </div><div style="font-family: Helvetica; font-size: 14px;" class="">which puts a burden on performance because the contents </div><div style="font-family: Helvetica; font-size: 14px;" class="">of a collection are unpredictable </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: </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=""> d </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=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">10.0 </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=""> </span><span style="color: rgb(187, 44, 162);" class="">tolerance </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=""> </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=""> **************************** !!! **************************************</div><div style="font-family: Helvetica; font-size: 14px;" class=""> Important is to see that this “for…” is in fact</div><div style="font-family: Helvetica; font-size: 14px;" class=""> a convenience solution for “while” and “repeat” constructs: </div><div style="font-family: Helvetica; font-size: 14px;" class=""> and thus a totally different beast compared to the "for in…” ! </div><div style="font-family: Helvetica; font-size: 14px;" class=""> *********************************************************************</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 </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=""> > </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5.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" 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=""> </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=""> </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> above for-loop, but still tedious to write!</div><div class=""><br class=""></div><div class="">What more can I write to convince? </div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">*** Please tell me if I am wrong, but: </div><div class=""><div class="">I am inclined to think that Functional Programming Minded</div><div class="">Colleagues are trying to push persistently their </div><div class="">(mathematically correct?) way of thinking upon Swift, </div><div class="">thereby ignoring that Swift is and should remain a </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 </div><div class="">epsilon(tolerance) value? ) </div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> </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>