Contents | Prev | Next

9.10 While statement

Description

While statements perform an action in a conditional loop as long as the loop condition is true, and include the following:

NOTE: The loop condition is evaluated before the statement in the while statement is executed so this statement may never be executed. Usually the statement in the while statement will perform some action that will eventually cause the loop condition to be false and terminate the execution of the loop.

Example

For example below is a very simple program which illustrates the use of the "while" statement.

   program ten(output);
   var
      count : 1..11;
   begin
      count := 1;
      while count <= 10 do
     begin
       writeln(count);
       count := count + 1;
     end
   end.

Syntax

(NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):

   while-statement = 'while' boolean-expression 'do' statement

Contents | Prev | Next