HP Pascal/iX Reference Manual (31502-90022)
Table Of Contents
- Top of Document
- Preface
- Chapter 1 Introduction
- Chapter 2 Language Elements
- Chapter 3 Data Types
- Chapter 4 Expressions
- Chapter 5 The Declaration Section
- Chapter 6 Statements
- Chapter 7 Program Structure
- Chapter 8 Procedures and Functions
- Chapter 9 Standard Routines
- Chapter 10 Input and Output
- Chapter 11 System Programming Extensions
- Chapter 12 Compiler Options
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