<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="">I like it!<div class=""><br class=""></div><div class="">Anything to keep heading down the cleaner syntax path as Swift cleans up so much of the visual noise that ObjC used to present.</div><div class=""><br class=""></div><div class="">That said, with. map and other capabilities, how often would this be used?<br class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 1:54 PM, Jason Pollack 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 dir="ltr" class="">I'd like to propose a small enhancement to the repeat loop.<div class=""><br class=""></div><div class="">Currently if we want to perform 'count' iterations in a loop, we need to do something like:</div><div class=""><br class=""></div><div class="">for _ in 0 ..< count {</div><div class=""> //Do something here</div><div class="">}</div><div class=""><br class=""></div><div class="">It looks and feels a little awkward. We need to create an unnamed variable, and it's easy to forget (especially for language newcomers) that the loop starts with 0 and doesn't include count.</div><div class=""><br class=""></div><div class="">We can also do:</div><div class=""><br class=""></div><div class="">var i = 0</div><div class="">repeat {</div><div class=""> //Some code</div><div class=""> i += 1</div><div class="">} while i < 10</div><div class=""><br class=""></div><div class="">This is worse, in that it introduces a variable in the outer scope, and puts the repeat count at the end. Plus, if the expression inside the repeat is complex, the value of i may never be incremented, or may be incremented more than once.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I propose the following:</div><div class=""><br class=""></div><div class="">repeat count {</div><div class=""> //Do something here</div><div class="">}</div><div class=""><br class=""></div><div class="">It's cleaner, and IMO clearer what this code is intended to do.</div><div class=""><br class=""></div><div class="">Naturally 'count' should be non-negative. A while clause is not needed, although I could imagine it being supplied, to create a construct such as:</div><div class=""><br class=""></div><div class="">var ok = true</div><div class="">repeat numberOfTimes {</div><div class=""> //Do something, possibly set ok to false</div><div class="">} while ok</div><div class=""><br class=""></div><div class="">This would repeat the loop a maximum of 'numberOfTimes', but could be ended early if some signal 'ok' is set to false (or, of course, by a break statement).</div><div class=""><br class=""></div><div class="">Thoughts?</div><div class=""><br class=""></div><div class="">Thanks!</div><div class="">-Jason-</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=x4uyz1zXl8lzAqqt7clW3PzY1MDX7Umk-2F-2BYOsBI6xdqW2GKREwBIk05AbnISLH8TWzzwb0ceeQBzavzgoMU7U8NHFaMJEDqtFBy474Ne4pUolB9-2FDIO-2Bqzx5K0GzMDSZm6VDrN30KhmFq44flOFj4f-2BrHPb8FZPvfXX-2Bmv6B3b6C09y8kKjRl5ZWw87igfaA6tHpFghbir1jH33SOizguQ-3D-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=""></div></div></body></html>