Describes the case multipath conditional statement
This statement is an alternative to the if-then-else conditional statement. The case construct is more efficient and easier to read when you need to execute one block of code among many, based on the value of a single parameter.
case <expression>
when <case1> then
<statements>
[when <cases2> then
<statements>]
...
[when <caseN> then
<statements>]
[else
<statements>]
end
There can be zero or more when-then statement blocks, though normally there will be more than one.
case x
when 1 then
display "x is equal to one"
when 2,3,4,5,6 then
display "x is a value between two and six"
else
display "x is greater than six or less than one"
end
The else block is optional. It can be used to implement a default action if no when conditions are met.
The following case example sets the string shortWeekday based on the value of dayNumber. There are seven weekdays, so if dayNumber is not 1, 2, 3, 4, 5, 6, or 7, then its value is considered to be invalid.
case dayNumber
when 1 then
shortWeekday = "Sun"
when 2 then
shortWeekday = "Mon"
when 3 then
shortWeekday = "Tue"
when 4 then
shortWeekday = "Wed"
when 5 then
shortWeekday = "Thu"
when 6 then
shortWeekday = "Fri"
when 7 then
shortWeekday = "Sat"
else
shortWeekday = "This is not a valid weekday!"
end