Re:Philosophy and "for" loops — more from Go and Rust
by pcwalton on Thursday July 11, 2013 @11:41AM
(#6026737)
It's not about performance gains; it's about making it harder to mess up. C-style for loops are easier to get wrong. (Try iterating backwards from 10 to 0 with an unsigned int loop index in C; most programmers get it wrong the first time due to underflow.) They are also more vulnerable to race conditions. (See "race on loop counter" at [1]; with first-class iterators you can create a separate binding for each iteration of the loop, eliminating this problem.)
[1]: http://golang.org/doc/articles/race_detector.html