Select…Case Statement

Runs one of many blocks of statements, because of a test expression.


[ @Strict ] _
Select [ Case ] test_expression [ Tol tolerance ]
    Case expression_list
        [ statements ]
    [ Case Else
        [ else_statements ] ]
End [ Select ]


Optional modifier specifies that you must supply tests for all possible values of test_expression.
test_expression can be an enumeration type (declared with Enum) that also has the modifier @Strict. If it does, you must use all the constants with the equality construct, and without Case Else. Other data types put no such limits on the syntax.
Mandatory expression of an elementary data type.
Optional floating-point constant specifies the tolerance for rounding errors when values are compared. See Tol Clause for more information.

Mandatory after Case, one or more expressions for tests with test_expression with a comma between each. It can be one of the constructs that follow:

Range construct

expression_1 To expression_2

Comparison construct

Is comparison_op expression

Equality construct


The range construct lets you compare a range of values. The value of expression_1 must be less than or equal to expression_2.

The comparison construct lets you use all the comparison operators: <, <=, >, >=, =, or <>.

The equality construct operates the same as Is =.

Optional one or more statements after Case that run if test_expression agrees with one of the expressions in expression_list.
Optional one or more statements after Case Else that run only if none of the expressions in the sets of expression_list agree with test_expression.
Completes the statement. You can also use End Select.


If test_expression agrees with one of the expressions after Case, the related block of statements that follows it runs. The block continues until the next Case, Case Else, or End Select. Then the statement after End Select runs. If more than one expression can agree, only the first one that agrees runs.

The line Case Else is related to the block else_statements. This block runs only when test_expression agreed with none of the sets of expressions that came before it. Although not mandatory, we recommend that you supply Case Else if unusual values of test_expression are possible. If none of the blocks that start with Case ran, the statement after End runs.

Changes in syntax with @Option

There are three areas where you can change the syntax of the statement:

See @Option Directive for more information.


Program FizzBuzz
Require ViviFire.IO

For num = 1 To 100
    Select Case num Mod 15
    Case 0
        PrintLine "fizzbuzz"
    Case 3, 6, 9, 12
        PrintLine "fizz"
    Case 5, 10
        PrintLine "buzz"
    Case Else
        PrintLine num
    End Select
End For

See also