Download Language Reference Manual

Transcript
5.11 REPEAT Statement
The REPEAT statement is a looping statement and executes one or more
statements until a specified condition is true. A REPEAT statement has the
following form:
REPEAT
{statement};...
UNTIL expression
statement
Any Pascal statement.
expression
Any Boolean expression.
Pascal always executes a REPEAT statement for one iteration; iterations
continue as long as the Boolean expression is FALSE. When specifying more
than one statement as the loop body to a REPEAT statement, do not enclose
the statements with the BEGIN and END reserved words. Multiple statements
are legal in the REPEAT loop body.
Consider the following example:
REPEAT
READ( x );
{Attempts to read at least one character}
IF ( x IN [’0’..’9’] ) THEN
BEGIN
{Keep count of numbers and increase total}
Digit_Count := Digit_Count + 1;
Digit_Sum := Digit_Sum + ORD( x ) - ORD( ’0’ );
END
ELSE
Char_Count := Char_Count+1; {Count characters}
UNTIL EOLN(INPUT); {Reads from default device until end of line}
For More Information:
•
On Boolean expressions (Section 2.1.3)
5.12 RETURN Statement
The RETURN statement passes control back to the caller of a PROCEDURE,
FUNCTION, PROGRAM, or module initialization or finalization section. A
RETURN statement is equivalent to a GOTO to a label placed just before the
END of the body, and in a PROGRAM, has the effect of stopping the program.
A RETURN statement has the following form:
RETURN [ return-value ]
5–10 Statements