[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For ordinal index variables:
for ordinal variable := initial value to final value do statement |
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 |
for pointer variable := initial address downto final address do statement |
@@ Set member iteration
The `for' statement is a count loop. For further information see section 8.1.7.5 for Statement.
`for' is defined in ISO-7185 Pascal and supported by all Pascal variants. Iteration of Pointers is a Borland Pascal extension. Set member iteration is an ISO-10206 Extended Pascal extension.
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. |
section 8.2.10.7 Set Types, section 8.6 Pointer Arithmetics