# Thread: for cycle with fixed data

1. ## for cycle with fixed data

is there some way to elaborate this line so that it works
Code:
```//------------------------------------------------------------------------------
int main()
{
int aaa  ;
for (aaa=0 ; aaa=3 , aaa=6 ,aaa=9 ;aaa+++)
{
printf("\n %d \n", aaa);
}
return 0;
}

//----------------------------------------------------------------------------```

2. Oh... there is ONE error: The expression a+++ is wrong. Everything else "works".

3. Originally Posted by flp1969
Oh... there is ONE error: The expression a+++ is wrong. Everything else "works".

.
Code:
```int main()
{
int aaa  ;
for (; aaa=3 , aaa=6 , aaa=9 ;)
{
printf("\n %d \n", aaa);
}
return 0;
}
.```

strange to me print 9 alone boh!!!

4. i mean something like that

Code:
```[int main()
{
int aaa  ;
for (aaa=0 ; aaa<=9 ; aaa++ )

if (aaa==3 || aaa==6 || aaa ==9)
{
printf("\n %d \n", aaa);
}
return 0;
}```

5. Maybe
for ( aaa = 3 ; aaa <= 9 ; aaa += 3 )

Cut out all the excess.

6. 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.