> I’d like to propose an addition of a useful method, especially for beginners 
> that also makes Swift much more readable in some situations: The addition of 
> a .times method to Integer type(s).

I’ve said it before, but I don’t think `times` is a good solution for learners. 
It teaches them a form of looping they will never use in practice and does not 
allow them to practice with ancillary loop skills like `break` and `continue`.

I think our best bet is to extend the `for` loop to allow a single number, 
meaning either `1…n` or `0..<n` (you can argue it either way), and also to 
allow the `variableName in` part to be omitted, meaning `_ in`. This gives us 
the pedagogical simplicity of a “do this N times” loop, but couches it in a 
form where, when the student moves on, more commonly used loop forms are a 
straightforward extension of that simple case.

        for 5 { print(“Hello!”) }
        for i in 5 { print(“Hello \(i)!”) }
        for i in 10..<20 { print(“Hello \(i)!”) }
        for i in 10...20 { print(“Hello \(i)!”) }

-- 
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to