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.

generic for_test
{
 for_test()
 {
   s = new set()
   s << +a << +b << +c
   
   for i s i.println()
 }
}

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.