Titan



for


The keyword defines a counter loop. The value of the index variable is increased, decreased or manipulated in such a way that after a certain number of execution loops a termination criterion is reached.


for ([ index_variable_declaration ] initial_value; condition; manipulator_expression) {  statement_block };


Example 1:

var integer j; 
for (j:=1; j<=10; j:= j+2) { log ("index variable: ", j) }

The loop variable j is declared in the first line. In the second line, a loop is defined. The initial value of the index variable (j) is 1. The index variable is increased by 2 every time the loop was executed. The loop execution terminates when the index value will have a value greater than 10. The statement block contains a log instruction, which will be executed 5 times resulting in five lines in the log.


Example 2:

for (var integer jj:=1; jj<=10; jj:= jj+2) { log ("index variable: ", jj) }

The only difference to the first example is that the index variable (jj) now is declared within the loop. It means that it will not be visible outside the loop.



BNF definition of for