4 ms·
I interpreted that line to be two separate clauses: firstly, a note that the statement that the correct generalisation for for loops is iterators, which were in
by MrJohz 3y ago
I interpreted that line to be two separate clauses: firstly, a note that the statement that the correct generalisation for for loops is iterators, which were introduced in Alphard; secondly, an unrelated point about how the C-style generalised for loop is more verbose for the simple case than existing syntaxes.
That is, the commenter was not asserting the supremacy of "from 0 to N" as a for-loop construct, but rather asserting the supremacy of iterators, and pointing out how poor the C-style syntax is even compared to its less-generalised cousins.
- adrian_b 3y agoBefore C and Alphard, all the "for" loops had control variables that took all values of some arithmetic progression. Even today, such simple loops with arithmetic progressions include an overwhelming majority of all "for" loops. The C syntax made writing these simple "for" loops more difficult, by having to write a lot of redundant symbols, instead of writing the minimum number of separators. Also for reading, the redundant symbols obscure the meaningful text. The C syntax allows the writing of "for" loops where the values of the control variables are not taken from a progression, but they are for instance the values of the links of a linked list. This kind of "for" loops can be written in a simple way by using iterators, without complicating the syntax of the loops with simple arithmetic progressions. In modern C++ there is no longer any case when you would want to use the C kind of "for", but the kinds of loops used by languages like C++ already existed in languages introduced at about the same time with C, e.g. Alphard and Clu.