Confuzed with braces please!

Hi, could someone please tell me the difference between the two below peices of code:

cout << "\nCounting forward:\n";
for (int i = 0; i < 10; ++i)
cout << i << " ";

and

cout << "\nCounting forward:\n";
for (int i = 0; i < 10; ++i)
{
cout << i << " ";
}

If i put in the braces does that mean everything inside it is carried out, so i can put more than one line, and if i dont put braces then only the 1 line below is part of the for loop

also...

everytime it checks the test and carries out the cout statement, how does it know to put the second test on the line below (and 3rd, and 4th, and 5th...), because im not using "\n" or "endl",
There is no difference in this case. You don't need braces if there is only one line within the loop.

If i put in the braces does that mean everything inside it is carried out, so i can put more than one line, and if i dont put braces then only the 1 line below is part of the for loop

That is correct.
Thanks for replying

everytime the for loop counts forward, how does it know to put each new number on a different line?
??? :)
anyone?
afaik it doesn't :p

the output of your prog is this :

Counting forward:
0 1 2 3 4 5 6 7 8 9 
ha, how daft of me. Thanks
Topic archived. No new replies allowed.