Node:for Statement, Next:while Statement, Previous:case Statement, Up:Statements
For ordinal index variables:
for ordinal_variable := initial_value to final_value do statementor
for ordinal_variable := initial_value downto final_value do statement
For sets:
for set_element_type_variable in some_set do statement
For pointer index variables:
for pointer_variable := initial_address to final_address do statementor
for pointer_variable := initial_address downto final_address do statement
The for statement is a control statement where an index variable assumes every value of a certain range and for every value the index variable assumes statement is executed. The range can be specified by two bounds (which must be of the same type as the index variable, i.e. ordinal or pointers) or by a set.
For ordinal index variables:
to
is specified, the index counter is increased by
one as long as initial_value is less or equal to final
value,
downto
is specified, it is decreased by one as long
as initial_value is greater or equal to final_value.
For pointer index variables:
to
is specified, the index counter is increased by
the size of the type the index variable points to (if it is a typed
pointer, otherwise by one if it is typeless) as long as
initial_address is less or equal to final_address,
downto
is specified, it is decreased by a
corresponding value as long as initial_address is greater or
equal to final_address.
Since gpc provides a flat memory modell, all addresses are linear, so they can be compared. Still, such loops should be used (if at all) only for iterating through successive elements of an array.
For sets:
Note: A modification of the index variable may result in unpredictable action.