Subsections

Statements

The assignment statement

statement
$\rightarrow$
expression$_1$ := expression$_2$ ;

The assignment statement assigns the value of expression$_2$ to expression$_1$. expression$_1$ must be an lvalue. A compile-time error is produced if the type of expression$_2$ is not assignment compatible to the type of expression$_1$. It is not defined which of the expressions is evaluated first (in case the expressions have side effects).

The expression statement

statement
$\rightarrow$
expression ;

The expression statement evaluates expression only for its side effects. The result is not used.

The delete statement

statement
$\rightarrow$
delete expression ;

This statement deletes the object referred to by expression. Expression must be of any array type, or null.

The if statement

statement
$\rightarrow$
if expression then statement$_1$ [ else statement$_2$ ]

The if statement evaluates expression. expression must be of type bool. If expression evaluates to true, statement$_1$ is executed. If expression evaluates to false and the optional else part is given, statement$_2$ is executed. The dangling-else ambiguity is resolved by connecting the else with the last encountered else-less if at the same block nesting level.

The for statement

statement
$\rightarrow$
for expression$_1$ := expression$_2$ to expression$_3$ [ by expression$_4$ ] do statement$_1$

The for statement repeats statement$_1$ a specified number of times. expression$_1$ denotes the loop value, which must be an lvalue; expression$_2$ the begin value; expression$_3$ the end value; expression$_4$ the step size. If the by part is omitted, the step size is 1. All expressions must be of type int. Expressions 2, 3, and 4 are evaluated only once, before statement$_1$ is executed. However, the evaluation order of the expressions is not defined. If the begin value is greater than the end value and the step size is positive, or if the begin value is smaller then the end value and the step size is negative, statement$_1$ is not executed at all. Otherwise, after each iteration of statement$_1$, expression$_1$ is incremented by the step size. Although considered poor programming practice, it is allowed to use expression$_1$ as lvalue within the for-loop.

The repeat statement

statement
$\rightarrow$
repeat statement$_1$ until expression ;

The repeat statement repeats statement$_1$ until expression evaluates to true. statement$_1$ is executed at least once. expression must be of type bool.

The while statement

statement
$\rightarrow$
while expression do statement$_1$

statement$_1$ is executed as long as the evaluation of expression yields true. expression must be of type bool.

The return statement

statement
$\rightarrow$
return [ expression ] ;

The return statement exits from the current subprogram. If the subprogram is a procedure, expression must be omitted. If the subprogram is a function, expression must be provided and assignment compatible to the return type of the function. The return value will be the result after evaluating expression.

The compound statement

statement
$\rightarrow$
[ var var_declaration_list ] begin [ statement_list ] end

statement_list
$\rightarrow$
statement [ statement_list$_1$ ]

The compound statement is both used for grouping statements, and for introducing local variables. If the optional var_declaration_list is provided, a new scope is introduced starting from the keyword var up to the keyword end.

K.G. Langendoen 2006-10-03