The for Statement


The for statement has the following form:

for object collection statement

where:

The name object is defined in the scope of the statements executed.

An example of a for loop is shown below.

space for_test
{
   for_test()
   {
       set = { 0 1 2 }
       for e set cout << e << "\n"
   }
}

The output of the program is shown below.

0
1
2

A for loop iterates over a collection - so an iterable collection must be specified in its construction.