5.4.2.10 Select Case Statement

A <select-case-statement> determines which <statement-block> to execute out of a candidate set.

 select-case-statement = "Select" "Case" WS select-expression EOS 
 *[case-clause] 
 [case-else-clause] 
 "End" "Select" 
 case-clause = "Case" range-clause *("," range-clause) EOS statement-block 
  
 case-else-clause = "Case" "Else" EOS statement-block 
 range-clause = expression  
 range-clause =/  start-value "To" end-value  
 range-clause =/    ["Is"] comparison-operator expression 
 start-value = expression 
 end-value = expression 
 select-expression = expression 
  
 comparison-operator = "=" / ("<" ">" ) / (">" "<") / "<" / ">" / (">" "=") /  ("=" ">") / ("<" "=") / ("=" "<") 

Runtime Semantics.

  • In a <select-case-statement> the <select-expression> is immediately evaluated and then used in the evaluation of each subsequent <case-clause> and <case-else-clause>

  • For each <case-clause>, each contained <range-clause> is evaluated in the order defined. If a <range-clause> matches a <select-expression>, then the <statement-block> in the <case-clause> is executed. Upon execution of the <statement-block>, execution of the <select-case-statement> immediately completes (and each subsequent <case-clause> is not evaluated).

    • If the <range-clause> is an <expression>, then <expression> is evaluated and its result is compared with the value of <select-expression>. If they are equal, the <range-clause> is considered a match for <select-expression>. Any subsequent <range-clause> in the <case-clause> is not evaluated.

    • If the <range-clause> starts with the keyword Is or a <comparison-operator>, then the expression "<select-expression> <comparison-operator> <expression>" is evaluated. If the evaluation of this expression returns the data value True, the <range-clause> is considered a match for <select-expression>. Any subsequent <range-clause> in the <case-clause> is not evaluated.

    • If the <range-clause> has a <start-value> and an <end-value>, then the expression "((<select-expression>) >= (<start-value>)) And ((<select-expression>) <= (<end-value>))" is evaluated. If the evaluation of this expression returns the data value True, the <range-clause> is considered a match for <select-expression>. Any subsequent <range-clause> in the <case-clause> is not evaluated.

  • If evaluation of each <range-clause> in each <case-clause> results in no match, the <statement-block> within <case-else-clause> is executed. If <select-expression> is the data value Null, only the <statement-block> within <case-else-clause> is executed.

  • If a <goto-statement> defined outside the <select-case-statement> causes a <statement> within a <statement-block> to be executed, none of <select-expression>, <case-clause>, or <range-clause are evaluated. A <goto-statement> can also cause execution to leave the <statement-block>. If a later <goto-statement> causes execution to re-enter the <statement-block>, the behavior is as specified by the rules defined for the execution of a <statement-block> within a <select-case-statement>.