VMS Help
PASCAL, Statements, WHILE
*Conan The Librarian (sorry for the slow response - running on an old VAX)
|
|
The WHILE statement is a loop that executes a statement while a
specified condition is true.
Syntax:
WHILE expression DO
statement
The 'expression' is any Boolean expression.
The 'statement' is any Compaq Pascal statement.
Compaq Pascal checks the value of the Boolean expression before
executing the loop body for the first time; if the expression is
FALSE, the loop body is not executed. If the initial value is
TRUE, loop iterations continue until the condition is FALSE.
When specifying more than one statement as the loop body to a
WHILE statement, enclose the statements with the BEGIN and END
reserved words, since the syntax calls for a single statement to
follow the DO reserved word. If you do not use a compound
statement for the loop body, Compaq Pascal executes the first
statement following the DO reserved word as the loop body.
WHILE NOT EOLN (INPUT) DO
BEGIN
READ (x);
IF NOT (x IN ['A'..'Z', 'a'..'z', '0'..'9'])
THEN
Err := Err + 1;
END;
This example reads an input character (x) from the current line.
If the character is not a digit or letter, the error count,
'Err', is incremented by one. The loop terminates when an
end-of-line on the INPUT is reached.
[legal]
[privacy]
[GNU]
[policy]
[netiquette]
[sponsors]
[FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.