Ruby’s for/in loop can have many statement:
for a in 1..2 do
expression 1
expression 2
..
end
But it seems for loop in C can only have one:
for (a = 0; a < 10; a ++) expression 1;
Is there any way to make multiply statement in the for loop in C?
Yes, formally speaking all loop statements in C take only one statement as the loop body. The same is true for branching statements (like
if) and virtually all other statements in C.However, that one statement can be a compound one. A compound statement begins with
{, ends with}and contains an arbitrary number of nested statements inside. (Note that there’s no;at the end of compound statement.)