This is a useful control construct if one of several paths through an algorithm must be chosen based on the value of a particular expression. SELECT CASE is more efficient than ELSEIF because there is only one expression that controls the branching. The expression needs to be evaluated once and then control transferred to whichever branch corresponds to the expressions value. An IF .. ELSEIF ... has the potential to have a different expression to evaluate at each branch point making it less efficient.
The syntax is as follows,
[name
![]()
:
] SELECT CASEcase-expr
![]()
[ CASE
case-selector
[
name
]
exec-stmts
] ...
[ CASE DEFAULT [
name
]
exec-stmts
]
END SELECT [
name
]
Note,
CASE constructs may be named -- if the header is named then so must be the END SELECT statement. If any of the CASE branches are named then so must be the SELECT statement and the END statement