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.