In many languages (a wide list, from C to JavaScript):
- commas
,
separate arguments (e.g.func(a, b, c)
), while - semicolons
;
separate sequential instructions (e.g.instruction1; instruction2; instruction3
).
So why is this mapping reversed in the same languages for for loops:
for ( init1, init2; condition; inc1, inc2 )
{
instruction1;
instruction2;
}
instead of (what seems more natural to me)
for ( init1; init2, condition, inc1; inc2 )
{
instruction1;
instruction2;
}
?
Sure, for
is (usually) not a function, but arguments (i.e. init
, condition
, increment
) behave more like arguments of a function than a sequence of instructions.
Is it due to historical reasons / a convention, or is there a good rationale for the interchange of ,
and ;
in loops?
;
not|
?" (or Why do we use 'else' not 'otherwise'?)) which is not case for one language, but a big number of them. An answer that e.g. "it was made in C as a shorthand for while loop (and multiple statements for inc were thought only later), and people didn't want to change it to avoid programmers' irritation" would be perfectly fine.