Contents | Prev | Next

9.7 If statement

Description

If statements either perform one of two actions, or conditionally perform a single action. If statements include the following:

Example

For example

   if x = y then
      writeln('x is equal to y);

is an if statement that conditionally performs a single action (i.e. the action specified by the then-part). When this if statement is executed the if-condition (i.e. x = y) is evaluated and if true the statement in the then-part (i.e. writeln('x is equal to y)) is executed, and if false then execution of the if statement is terminated.

Here is another example

   if x = y then
      writeln('x is equal to y)
   else
      writeln('x is not to y);

is an if statement that performs one of two actions (i.e. either the action specified by the then-part or the action specified by the else-part). When this if statement is executed the if-condition (i.e. x = y) is evaluated, and if the value of the test condition is true then the statement in the then-part (i.e. writeln('x is equal to y)) is executed, and if the value of the test condition is false then the statement in the else-part (i.e. writeln('x is not equal to y)) is execuited.

Syntax

(NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):

   if-statement = 'if' boolean-expression 'then' statement [ else-part ]

   else-part = 'else' statement

Contents | Prev | Next