The condition is what controls the loop.
for (initialization ; condition ; update)
The idea is that in a for loop, the loop is controlled by a counter, so it will run a determinate, finite number of times. The counter is, traditionally, increased after every execution of the loop. Once the condition is false, the loop ends and the code moves on.
for (int i = 0; i < 7; i++)
That for loop would run 7 times. After running for i = 6, it would be incremented to seven and seven is not less than seven. So the loop would end. All loops in C++ are condition driven.
Also note the difference between a regular bracket and a curly brace. Curly brackets denote scope and code block. Normal brackets are for calling functions and storing conditions.
Read this:
http://www.cplusplus.com/doc/tutorial/control/
EDIT: By the way... those single line loops? Those are always allowed. If, after a control structure statement (exception being switch, I believe), you only have one statement, you can skip the curly brackets. That includes all loops and the if/else if/else structures.
1 2
|
while (true)
cout << "Annoyed yet?"; // totally legal
|
EDIT 2: (Wow this site is lagging today) Also denote the difference between a line and a statement.
cout << "hey"; cout << " this"; cout << " is"; cout << " bad"; cout << " style";
All that is five statements. You could cram the entirety of main onto one line and as long as you had the semicolons in their proper places, C++ doesn't care about the leading whitespace. This would even work, I think:
cout << "even";cout << " worse";cout << " style";