[swift-evolution] repeat loop enhancement

Brent Royal-Gordon brent at architechies.com
Mon Dec 14 05:26:28 CST 2015


> Why not define a times() or timesRepeat() method on Int taking a closure to execute multiple times, like Erica recently posted and which is common in other languages like Ruby, Smalltalk or (I think) Scala:

In the teaching context, the answer is because it doesn’t actually teach you anything that can be extended to other parts of the language. `times` is a great fit for Ruby because many other Ruby looping constructs are also methods on an object (particularly the `each` loop), and because it works with all the usual loop flow control like `break`. None of these things are true about Swift, so you’re effectively teaching your students a dead end.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list