# Thread: for structure whitout {}?

1. ## for structure whitout {}?

Code:
```for ( int i = 0; i <= 10; i++ ) ;
cout << setw( 2 ) << i << "! = " << factorial( i ) << endl;

return 0;

}```
Ok i am learning functions right now and was wondering why does the code in the secound line keep repeating if their are no { } between it?

Thanks alot.
Some things i have to ask sorry.
Cya

2. >for ( int i = 0; i <= 10; i++ ) ;
Remove the semicolon.

3. Oh that was typing mistake but my question is still the same.
Thanks.

4. You mean:
Code:
```for ( int i = 0; i <= 10; i++ )
cout << setw( 2 ) << i << "! = " << factorial( i ) << endl;```
Well, the reason would be that with a single statement, the braces are unnecessary.

So this would be ok:
Code:
```if (condition)
line_of_code();
else
line_of_code();

while (condition)
line_of_code();```

5. If the body of a loop is a single statement then the braces can be omitted. These two loops are equivalent:
Code:
```for ( int i = 0; i < 10; i++ ) {
cout<< i <<'\n';
}

for ( int i = 0; i < 10; i++ )
cout<< i <<'\n';```
If you have more than one statement in the body then you must use braces. These two loops are not equivalent:
Code:
```for ( int i = 0, j = 9; i < 10; i++, j-- ) {
cout<< i <<'\t';
cout<< j <<'\n';
}

for ( int i = 0, j = 9; i < 10; i++, j-- )
cout<< i <<'\t';
cout<< j <<'\n';```

6. I see what you mean now.

I tried the examples you gave also and it's cool.

Thanks both of you.

I sometimes learn to much then have to go back when i see something i don't quite understand.

Thanks alot.
cya