next up previous
Next: Example Of SELECT CASE Up: Control Flow Previous: Scope of DO Variables

 

SELECT CASE Construct

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,

 
 [  tex2html_wrap_inline21419  name  tex2html_wrap_inline21421 : ] SELECT CASE  tex2html_wrap_inline21419  case-expr  tex2html_wrap_inline21421 

[ CASE tex2html_wrap_inline21419  case-selector tex2html_wrap_inline21421 [ tex2html_wrap_inline21419  name tex2html_wrap_inline21421 ]

tex2html_wrap_inline21419  exec-stmts tex2html_wrap_inline21421 ] ...

[ CASE DEFAULT [ tex2html_wrap_inline21419  name tex2html_wrap_inline21421 ]

tex2html_wrap_inline21419  exec-stmts tex2html_wrap_inline21421 ]

END SELECT [ tex2html_wrap_inline21419  name tex2html_wrap_inline21421 ]

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




next up previous
Next: Example Of SELECT CASE Up: Control Flow Previous: Scope of DO Variables

Adam Marshall ©University of Liverpool, 1996
Wed Oct 9 17:57:29 BST 1996