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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PASCAL</strong> STATEMENTS<br />

Example 1<br />

CASE<br />

END;<br />

Alphabetic OF<br />

'A','E','I'p'O','U' : Alpha_Fla~ := Vowel~<br />

"~(I : Alpha .... Fla~:,~ != SometimE-'s<br />

OTHERWISE Alpha_Flag := Consonant<br />

This example assigns a value to Alpha Flag depending on the value of<br />

the character variable Alphabetic.<br />

5.4 REPETITIVE STATEMENTS<br />

Repetitive statements specify loops, that is, the repetitive execution<br />

of one or more statements. <strong>PASCAL</strong> provides three repetitive<br />

sta tements:<br />

• FOR statement<br />

• REPEAT statement<br />

• WHILE statement<br />

These are described in the following sections.<br />

5.4.1 The FOR Statement<br />

The FOR statement specifies the repetitive execution of a statement<br />

based on the value of an automatically incremented or decremented<br />

control variable.<br />

Forma t<br />

FOR control variable<br />

-= initial value {TO } final value DO statement;<br />

DOWNTO<br />

where:<br />

control variable<br />

initial value<br />

final value<br />

specifies the name of a simple variable of<br />

any scalar type except a real type.<br />

specifies an expression of the same type as<br />

the control variable.<br />

specifies an expression of the same type as<br />

the control variable.<br />

The control variable, the initial value, and the final value must all<br />

be of the same scalar type, but cannot belong to one of the real<br />

types. The repeated statement cannot change the value of the control<br />

variable. The control variable must be a simple variable; that is,<br />

it cannot be an element of an array, a field of a record, the object<br />

of a pointer reference, or a file buffer variable.<br />

At run time, completion tests are performed before the statement is<br />

executed. In the TO form, if the value of the control variable is<br />

less than or equal to the final value, the loop is executed, and the<br />

control variable is incremented. When the value of the control<br />

variable is greater than the final value, execution of the loop is<br />

complete.<br />

5-8

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

Saved successfully!

Ooh no, something went wrong!