by brudgers · 10y ago · 0 comments
https://github.com/apple/swift-evolution/blob/master/proposa...
https://github.com/apple/swift-evolution/blob/master/proposa...
https://github.com/apple/swift-evolution/blob/master/proposa...
https://github.com/apple/swift-evolution/blob/master/proposa...
I just spent a while reading about both stride and for ... in, and I feel like there are any number of cases where I would rather use a C-style for loop.
for i in range(10):
instead.
for item in sequence:
which is somewhat general (sequences include lists, dicts, strings, tuples, generators, text files and more [2]), and it covers a wide range [1] of use cases.
[1] Pun not intended.
[2] Basically, any iterable. This include custom iterables you can define, which can then be iterated over using the same standard for loop. A unifying feature of the language:
"The use of iterators pervades and unifies Python."
Could you use a while loop instead?
I feel like (as long as the numerical case optimizes to the same thing) the for-in loop (and occasional use of the while loop) is clearer.
// old
for x: Thing? = thing; x != nil; x = x.parent {
...
}// and now
var x: Thing? = thing
while x != nil {
...
x = x.parent
}It was the only case i've really missed it.. unless theres a better way to do it that im not aware of..
But the for c-style loop for numbers is really not needed
In Swift 3.0 they'll remove the deprecated syntaxes.