by andybak · 10y ago · 0 comments
It always struck me as a fairly warty syntax.
Consider Python where you usually do:
for item in iterator
If you want an integer sequence it's: for integer in range(1, 100)
and for those rare occurrences where you need an integer index as well: for index, item in enumerate(iterator)
Swift seems to have a similar approach. Why would you ever want the C-style iterators?`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