What is the full "for" loop syntax in C (and others in case they are compatible) ?

Posted by fmsf on Stack Overflow See other posts from Stack Overflow or by fmsf
Published on 2008-11-09T21:40:34Z Indexed on 2010/04/13 18:13 UTC
Read the original article Hit count: 333

Filed under:
|
|
|

I have seen some very weird for loops when reading other people's code. I have been trying to search for a full syntax explanation for the for loop in C but it is very hard because the word "for" appears in unrelated sentences making the search almost impossible to Google effectively.

This question came to my mind after reading this thread which made me curious again.

The for here:

for(p=0;p+=(a&1)*b,a!=1;a>>=1,b<<=1);

In the middle condition there is a comma separating the two pieces of code, what does this comma do? The comma on the right side I understand as it makes both a>>=1 and b<<=1.

But within a loop exit condition, what happens? Does it exit when p==0, when a==1 or when both happen?

It would be great if anyone could help me understand this and maybe point me in the direction of a full for loop syntax description.

© Stack Overflow or respective owner

Related posts about c

    Related posts about syntax