31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PASCAL</strong> STATE~ENTS<br />

5.4.3 The WHILE Statement<br />

The WHILE statement causes one or more statements to be executed while<br />

a specified condition is true.<br />

Fo rrna t<br />

where:<br />

WHILE expression DO statement;<br />

expression<br />

specifies a Boolean expression.<br />

The WHILE statement causes the statement following the word DO to be<br />

executed while the expression is true. Unlike the REPEAT statement,<br />

the WHILE statement controls the execution of only one statement.<br />

Hence, to execute a group of statements repetitively, you must use a<br />

compound statement. Otherwise, <strong>PASCAL</strong> repeats only the single<br />

statement immediately following the word DO.<br />

The expression is evaluated before the statement is executed. If the<br />

expression is initially false, the statement is never executed. The<br />

repeated statement must change the value of the expression. If the<br />

value of the expression never changes, the result is an infinite loop.<br />

Example 1<br />

l"'HILE NOT EOF(Filel) DO<br />

READL.N(Fil(·?l) y<br />

This statement reads through to the end of the text file Filel.<br />

Example 2<br />

WHILE NOT EOLN(INPUT) DO<br />

BEGIN<br />

/:;:EAD(X) ;<br />

IF NOT (X IN ['A' •• 'Z','a' •• 'z','O' •• '9'J) THEN<br />

IE r T' ::::: E In' + 1<br />

END;<br />

This example reads an input character from the current line on the<br />

terminal. If the character is not a digit or letter, the error count<br />

(Err) is incremented by one.<br />

Example 1<br />

SUITt != 0;<br />

Ntests ::::: 1;<br />

AV9 := 100;<br />

WHILE (AV9 >= 90) AND (Ntests

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!