Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
for is a keyword to start a for-loop.
Prefer algorithms over loops [1][2]. See Exercise #9: No for-loops to learn how to do so.

For loop syntax
for ( /* initialization */ ; /* breaking condition */ ; /* after-loop operation */ ) |

For-loop example
#include <iostream> |
The code above generates the following screen output:
0: Hello! |
Range-based for
C++11 supports a range-based for:
#include <vector> |
Note that the example initializes the std::vector with an initializer list.
Technical note: the code shown did not compile using the G++ 4.4.5 compiler, which is supplied with the Qt Creator 2.0.0 IDE, but is expected to compile in G++ 4.6 [3].
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.