|
|
|
|
|
by DonFromWyoming
3698 days ago
|
|
For the simple case with a single iterator, yes the C-style for loop isn't as concise. However, there are lots of real-world situations where there is not a single iterator (e.g. looping through 2 arrays). Having to go back to 'while(boolean) { }' loops with initializers outside of the loop and incrementors at strange places inside the loop is much more confusing and error prone. |
|
`for (l, r) in zip(c1, c2) {`
It is not simply motivated by making code concise, I would say `for num in collection.reverse()` is less error prone and clearer than `for (var i = collection.count; i >= 0; i--) { var num = collection[i] ... }`
The reverse collection iterator is computed lazily too, so there is no little perf overhead