Conditional statement

A conditional statement is a rule which helps to decide what to do depending on a variable value.

There are two types of conditional statements :

If (condition) then body1 else body2 :   If the condition of the operator 'if-else' is true, it passes the control to the first operator in body 1. After all operators in body 1 have been executed, it passes control to the operator that follows the operator 'if-else'. If the condition of the operator 'if-else' is false, then:

- if there is the key word 'else' in the operator 'if-else', then it passes the control to the first operator in body 2. After all operators in body 2 have been executed, it passes control to the operator that follows the operator 'if-else';

- if there is no key word 'else' in the operator 'if-else', then it passes the control to the operator that follows the operator 'if-else'.


CASE (variable) OF.... : The CASE operator provides a structured equivalent to a sequence of IF... THEN... ELSE statements on the same variable.  

The CASE statement is more elegant, more efficient, and easier to maintain than multiple IF.. THEN... ELSE nestings.

Example :

CASE age OF

0..3: write('Baby');

4..14 : write('child');

14..18 : write ('Teenager')

19..150 : write('Adult');

END;


Comment : In some computing languages (C, PHP, java...) the CASE statement is replaced by a SWITCH statement.