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?