Liste des Groupes | Revenir à cl c |
On 16/04/2025 13:08, Michael S wrote:[...]
When languages used to be 1-based, it was easy. Then 0-based came along,
and typically iteration changed from 1..N inclusive, to 0..N-1 inclusive.
[...]
Oh, now you could interpret a written above as statement of superiority
of C syntax. So, no, it is not. Those are *minor* points.
Here's some C code to print the elements of an array:
static char* table[] = {"one", "two", "three", "four", "five"};
for (int i=0; i<sizeof(table)/sizeof(table[0]); ++i)
printf("%d %s\n", i, table[i]);
And here is how I'd write it using the 'minor' advantages of my syntax:
static []ichar table = ("one", "two", "three", "four", "five")
for i, s in table do
println i, s
end
To me, the differences in that for-loop are like chalk and cheese.
(Note that the latter is 1-based, but it is not apparent in the code;
the outputs are numbered 1 to 5. The C is zero-based, and that has to be
specified. The outputs are numbered 0 to 4.
Moreover, I could have specified a different array base, and the loop
remains unchanged.)
Les messages affichés proviennent d'usenet.