Back
Contents Enumerating loop (for)

An enumerating loop goes through a list or a range from arbitrary elements. Each element of the list is once assigned in sequence the loop variable, and implemented afterwards the internal instructions of the loop. Loops are used, if an instruction is to be implemented repeated.

In the program structure chart the for loop is represented exactly like the normal repetition loop by two rectangles:



The outside rectangle is marked with the loop variable and the elements which can be enumerated. The internal rectangle contains the enclosed instructions.
If the loop is to run over a quantity from elements, these can be indicated for example as enumerating, in addition the individual elements are separately specified by commas:
2,4,5
The numbers are then assigned to the variable in sequence.

If the loop is to run over a sequential range from values, this is indicated by instruction range:
range(10)
Produces beginning starting from 0 a quantity of whole numbers, and ends before the 10. The values 0 to 9 are thus produced.
range(4,10)
Produced beginning starting from 4 a quantity of whole numbers, and ends before the 10. The values 4 to 9 are thus produced.