Re:Apple’s Use of Swift in iOS 13
by ShamelessC on Thursday September 26, 2019 @05:51PM
(#21085967)
It's actually more curious that they didn't have iterator style loops from the beginning. It's a pretty standard feature in newer languages and even plenty of older languages are adding support for it.
[ Parent
| on HN ]
Re:Apple’s Use of Swift in iOS 13
by NobodyNada on Thursday September 26, 2019 @05:58PM
(#21086030)
Swift had iterator-style loops from the beginning. It also initially supported C-style "for (i = 0; i < j; i++)" loops, but they were removed very early on (because in practice, they're rarely used for anything except iteration, and iterator-style loops are much more readable and less error-prone).
I never looked at Swift, but for example how do you wright 10 times "hello world" on the command line if you don't have for loops ?
You could do it with a while loop (if it exists in Swift) but I'm at a loss as to why you would remove a for loop from a programming language.
Re:Apple’s Use of Swift in iOS 13
by NobodyNada on Friday September 27, 2019 @12:42PM
(#21093805)
Iterator-style loops are much clearer and more concise in almost all cases. In this case you can iterate over a range:
for i in 0..<10 {
print(i)
}