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