HP Pascal/iX Reference Manual (31502-90022)

6-: 12
Example
sum := 0;
count := 0;
REPEAT
writeln('Enter trial value, or "-1" to quit');
read (value);
sum := sum + value;
count := count + 1;
average := sum / count;
writeln ('value = ', value, ' average = ',average)
UNTIL (count >= 10) OR (value = -1);
.
.
REPEAT
writeln (real_array[index]);
index := index + 1;
UNTIL index > limit;
WHILE .. DO
The WHILE statement executes a statement repeatedly as long as a given
condition is
true
. The WHILE statement consists of the reserved word
WHILE, a Boolean expression (the condition), the reserved word DO, and a
statement.
When the system executes a WHILE statement, the following occurs:
1. It evaluates the condition.
2. If the condition is true, it executes the statement after DO, and
then re-evaluates the condition. When the condition becomes
false, execution resumes at the statement after the WHILE
statement.
3. If the condition is false at the beginning, the system never
executes the statement after DO.
The statement:
WHILE condition DO statement
is equivalent to:
1: IF condition THEN
BEGIN
statement;
GOTO 1;
END;
Usually a program modifies data at some point so that the condition
becomes
false
. Otherwise, the statement repeats indefinitely.
Syntax
While_statement