Originally Posted by
ilkamalo
strange to me print 9 alone boh!!!
I said it works, not if it's doing what you want...
The for statement works with 3 arguments: initialization, condition to remain in loop and update:
Code:
for (init; cond; upd) { ... }
.
It is a simplified way to write:
Code:
init;
while (cond)
{
...
upd;
}
What you are doing is:
Code:
// for (; aaa = 3, aaa = 6, aaa = 9;) ...
while ( aaa=9 ) { printf( " %d\n", aaa ); }
Since the comma operator will evaluate the sub-expressions from left to right, 'aaa=3, aaa=6' will be discarded. Note the '=' operator. When you do an assignment, the resulting value (9) is considered as true, so the loop never ends, and aaa will be always 9.
It is not "strange". It is what you said the compiler to do.