CASE statement

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

CASE statement

mapp Services V5.16

The CASE statement can be used to group together several conditional statements with the same conditional variable into a single construct.

Syntax

CASE <expression> OF
    <value1> : <statement_list1>
    <value2>, <value3> : <statement_list2>
    <value4>..<value5> : <statement_list3>
    ELSE  <statement_list4>
END_CASE;

A CASE statement is executed as shown below:

If <expression> has <value1>, then the <statement_list1> statements are executed.

If <expression> has <value2> or <value3>, then the <statement_list2> statements are executed.

If the value of the expression in <expression> is in the range from <value4> to <value5>, then the <statement_list3> statements are executed.

If <expression> does not have any of the specified values, then the <statement_list4> statements are executed.

If the same statements should be executed for multiple values of expression <expression>, then these values can be written one after the other, separated by commas.

If the same statements should be executed for multiple consecutive values of expression <expression>, the minimum and maximum values must be separated by "...".

The <statement_listx> statement lists consist of no statements, one statement or multiple statements.

The ELSE section is optional. If <expression> has none of the specified values and the ELSE section is missing, no statement is executed.

Example

CASE Var1 OF
    1, 5: Var2 := 10;
    2:    Var2 := 20;
    6..9: Var2 := 30;
    ELSE  Var2 := 40;
END_CASE;

If "Var1" has the value 1 or 5, then "Var2" has the value 10 after execution of this CASE statement.

If "Var1" has the value 2, then "Var2" has the value 20 after execution of this CASE statement.

If "Var1" has the value 6, 7, 8 or 9, then "Var2" has the value 30 after execution of this CASE statement.

If "Var1" does not have any of the specified values, then "Var2" has the value 40 after execution of this CASE statement.