Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Keyword for starting a for-loop.
Prefer algorithms over loops [0][1]. See Exercise #9: No for-loops
to learn how to do so.
for ( /* initialization */ ; /*
breaking condition */ ; /* after-loop operation */ )
{
// The code block that will be repeated while the breaking condition is
true
}
{
for (
int i=0; //Create an in-loop integer
variable called i
i!=10; //Enter loop while i!=10
++i) //After looping,
increment i
{
std::cout << i << ":
Hello!\n";
}
}
The
code above generates the following screen output:
0: Hello!
1: Hello!
2: Hello!
3: Hello!
4: Hello!
5: Hello!
6: Hello!
7: Hello!
8: Hello!
9: Hello!
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.