|
|
|
|
|
by UIZealot
2144 days ago
|
|
It's kind of sad that "for" is the keyword programming languages settled on for the loop construct. Ever since its counterpart "do" was dropped from the for-statement, it's just been utterly nonsensical. I mean how on earth does the word "for" convey a loop? With the recently designed languages like Go and Swift taking so many cues from the Pascal side of the ALGOL language family, how nobody thought to pick up "repeat" or "loop" is simply beyond me. |
|
Many languages only use `for` to mean a for-each style loop where it reads quite naturally:
Python - `for n in range(1,10)`
Ruby - `for i in 0..10`
Rust - `for n in 1..10` (also picked up the bare `loop`)
Others support for-each style loops along with the less than ideal C-style for loop:
JavaScript - `for (n of [1,2,3])` (second attempt, for-in has too many gotchas.)
Java - `for (int n : {1,2,3})`
Otherwise I agree that `while` reads far more naturally. I guess they must have wanted to minimize the number keywords in Go.