Next: , Previous: Flush, Up: Reference



for

Synopsis

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

@@ Set member iteration

Description

The for statement is a count loop. For further information see for Statement.

Conforming to

for is defined in ISO 7185 Pascal and supported by all known Pascal variants. Iteration of Pointers is a Borland Pascal extension. Set member iteration is an ISO 10206 Extended Pascal extension.

Example

     program ForDemo;
     var
       CharSet: set of Char;
       c: Char;
       n: Integer;
       Fac: array [0 .. 10] of Integer;
       PInt: ^Integer;
     begin
       CharSet := ['g', 'p', 'c'];
       for c in CharSet do
         WriteLn (c);  { prints `c', `g', `p' in three lines }
       Fac[0] := 1;
       for n := 1 to 10 do  { computes the factorial of n for n = 0 .. 10 }
         Fac[n] := Fac[n - 1] * n;
       {$X+}
       { prints n! for n = 0 .. 10 }
       for PInt := @Fac[0] to @Fac[10] do
         WriteLn (PInt - @Fac[0], '! = ', PInt^)
     end.

See also

Keywords, Set Types, Pointer Arithmetics