CASE statement
Provides a multi-branch decision based on the value of a single expression.
Syntax
expression
WHENvalue
[ OR WHENvalue
] . . . THENOTHERWISEblock
statement
END [ CASE ]ExampleThe following fragment shows a simple example of a CASE statement:
Notes
- Each
value
must have the same data type asexpression
. If the data types do not match, the compiler reports an error.- You can specify any number of WHEN clauses within the CASE statement.
- You can specify only one OTHERWISE clause for a CASE statement. If you use the OTHERWISE clause, it must be the last branch in the statement.
- When a CASE statement is executed, the AVM evaluates
expression
and evaluates eachvalue
for each branch in order of occurrence until it finds the firstvalue
that satisfies the condition. At that point the AVM executes that branch and does not evaluate any othervalue
for that branch or any other branches. If no matchingvalue
is found, then the OTHERWISE branch is executed, if given. If the OTHERWISE branch is not given and no matchingvalue
is found, then no branch of the CASE statement is executed and execution continues with the statement after the CASE statement.- After a branch of the CASE statement is executed, the AVM leaves the CASE statement and execution continues with the statement following the CASE statement.
- If a LEAVE statement is executed within any branch of a CASE statement, the AVM leaves the closest block (other than a DO block) that encloses the CASE statement.
OpenEdge Release 10.2B
|