next up previous contents
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_inline21746  name  tex2html_wrap_inline21748 : ] SELECT CASE  tex2html_wrap_inline21746  case-expr  tex2html_wrap_inline21748 

[ CASE tex2html_wrap_inline21746  case-selector tex2html_wrap_inline21748 [ tex2html_wrap_inline21746  name tex2html_wrap_inline21748 ]

tex2html_wrap_inline21746  exec-stmts tex2html_wrap_inline21748 ] ...

[ CASE DEFAULT [ tex2html_wrap_inline21746  name tex2html_wrap_inline21748 ]

tex2html_wrap_inline21746  exec-stmts tex2html_wrap_inline21748 ]

END SELECT [ tex2html_wrap_inline21746  name tex2html_wrap_inline21748 ]

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 contents
Next: Example Of SELECT CASE Up: Control Flow Previous: Scope of DO Variables

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.