Trail: PROIV Documentation > Developer > PROIV Developer > Developing Functions > Events and Logic > CASE

 

 

Purpose

CASE selects a statement or block of statements for execution if a specified condition is met.
 

Syntax

CASE case-selector
WHEN case-list: statement or block
{OTHERWISE: statement or block}
ENDCASE
 

Operation

case-selector  is any expression.

case-list
 consists of one or more values of the same type as the selector, in any order, separated by commas.  A negative number constant will not be accepted. 

A value may appear only once within a CASE statement and it is associated with the statement or block of statements to its right.
 

Remarks

CASE is similar to IF-THEN-ELSE ENDIF in that it is a conditional statement.

Unlike IF THEN ELSE ENDIF the CASE statement allows the selection to be made from more than two statements or blocks.  In a CASE statement constant values are associated with each executable statement or block. 

CASE executes the statement or block labeled by the value that equals a specified expression.  If case-selector equals one of the values in case-list, the statement or block to the right of the label is executed at run time. 

If the case-selector does not equal one of the values in case-list, the statement or block to the right of OTHERWISE is executed.  If there is no OTHERWISE clause, control is passed to the statement following ENDCASE.

An optional CONTINUE clause may be included if required.  The CONTINUE statement causes execution of the statement or block that directly follows the next case-list, even though the selector has already matched one case and does not equal the next case.  The CONTINUE statement overrides the normal control within a CASE statement because control is not passed to the statement following the ENDCASE.
 

Example

This CASE statement compares the value in the expression MAR-STAT to the cases "MARRIED", "SINGLE", "DIVORCED", and "SEPARATED".

If the value of MAR-STAT is equal to any of the cases, the statement or block to the right of that case is executed.

CASE MAR-STAT
                WHEN "MARRIED":
                                statement-block1
                WHEN "SINGLE":
                                statement-block2
                WHEN "DIVORCED":
                                statement-block3
                WHEN "SEPARATED":
                                statement-block4

ENDCASE
 

Comment on this topic

Topic ID: 520027