Re:Swift's Evolution
by mikeash on Saturday June 03, 2017 @12:40PM
(#14477162)
When you do need an integer counter, the best way to have it is to create a new collection consisting of (index, element) pairs. Swift (and many other languages) make this easy:
There are some cases where the C style for loop is the most natural way to express something. For example, looping over NULL-terminated array of pointers is nicely expressed with one (Swift 2-ish pseudocode):
But these situations are really rare, and when you do encounter them, it's not a big deal to transform them into a while loop:
[ Parent
| on HN ]