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

9.95 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 section 8.1.7.5 for Statement.

Conforming to

`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.

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

section 8.2.10.7 Set Types, section 8.6 Pointer Arithmetics



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