[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

#### 8.1.7.5 for Statement

For ordinal index variables:

    for ordinal variable := initial value to final value do
      statement

or

    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
      statement

or

    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:

- If ``to'` is specified, the index counter is increased by one as long as initial value is less or equal to final value,
- if ``downto'` is specified, it is decreased by one as long as initial value is greater or equal to final value.

For pointer index variables:

- If ``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,
- if ``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:

- statement is executed with the index variable (which must be ordinal and of the same type as the set elements) assuming every element in some set, however note that a set is a not-ordered structure.

Note: A modification of the index variable may result in unpredictable action.

### See also

section 8.2.10.7 Set Types, section 8.6 Pointer Arithmetics, section 8.1.7.7 repeat Statement, section 8.1.7.5 for Statement

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html