Description
The select case statement marks the beginning of a "select block," which must end with an end select statement. You can use a select block to conditionally execute a block of statements based on a number of tests that you specify.
When there is only one test, it's often more convenient to use a if...[else]...end if block. A select block is useful when there are two or more conditions to test.
If you use Syntax 1, targetExpr must be a numeric or string expression. Each testExpr has the following syntax:
[ = | != | < | <= | > | >= ] expr
where expr is an expression of the same type as targetExpr. When the select block executes, targetExpr is compared against each testExpr in order. If the testExpr does not include a comparison operator (<, >, etc.), then targetExpr is compared for equality with expr; otherwise targetExpr is compared with expr using the indicated operator.
If the comparison of targetExpr with expr is true, the statementBlock (if any) following that case statement is executed; then execution continues at the first statement after end select. If none of the comparisons in any case statement is true, the statementBlock (if any) following the case else statement is executed; then execution continues at the first statement after end select. Each statementBlock can consist of any number of executable statements, possibly including other select...end select blocks.
If you use Syntax 2, each booleanExpr must be a numeric expression that can be evaluated as "true" (nonzero) or "false" (zero).
Typically, booleanExpr will be an expression that includes operators such as and, or, >, <, etc.
When the select block executes, each booleanExpr is evaluated in order, until one is found that is nonzero ("true").
Then the statementBlock (if any) under the corresponding case statement is executed; then execution continues at the first statement after end select.
If every booleanExpr is zero ("false"), the statementBlock (if any) following the case else statement is executed;
then execution continues at the first statement after end select.
Note 1:
Syntax 2 is a specialized form that works only for integer expressions and integer compile-time constants. It translates to a C switch statement, which is more readable than the C translation of syntax 1. Another advantage is performance: a switch statement can often be compiled to a jump table.