Um, "for (I=0;I<N;I+=5) {" is fewer characters than "for I from 0 to N by 5 do".
Um, "for (I=0;I<N;I+=5) {" is fewer characters than "for I from 0 to N by 5 do".
The argument “is more keystrokes” in this context is beyound what i can comprehend.
The syntactically equivalent, but non-verbose, is "for I ∈ 0:N:5 ⟨", which beats easily C.
for i 0:N:5 {
// loop body
}
By the way, the same should have been done with if and while: optional parentheses, mandatory braces: if a == b {
// code
}
while idx < end {
// code
}Still... when did that syntax come out? Was it in Algol 68, or PL/I? It seems a bit unfair to complain about C being verbose if it was shorter than anything else available at the time.
When later implemented, including in an Algol 68 variant that inspired the UNIX Bourne shell, "∈" was replaced with "in", which could be written with ASCII.
Algol 68 could use either keyword pairs, like "do" and "od" (which became "do" and "done" in the UNIX Bourne shell) or, optionally, various kinds of parentheses in their place, for conciseness.
The notation "0:N:5" or "0:N", when the step is 1, for arithmetic progressions is ancient. Even Fortran used it, but with the mistake of using comma instead of colon, which introduced a syntactic ambiguity, because comma was also used for other purposes. Using colon started with Algol 60, but that one preferred keywords instead of symbols in the arithmetic progressions used inside "for", so it did not use the notation consistently.
Fortran in 1954 or the language of Heinz Rutishauser, in 1951 (the first one with a "for" statement), were already much more concise than C.
for (I=0;I<N;I+=1)
versus
for I from 0 to N do