Select

Begins a multi-way branch statement that tests an expression against multiple values

Keywords

Parameters & Returns

Parameters

This function takes no parameters.

Returns

Void

Quick Summary

Begins a multi-way branch statement that tests an expression against multiple values

Technical Exegesis...

Begins a multi-way branch statement that tests an expression against multiple values. Syntax is Select expression followed by Case statements. Evaluates the expression once, then compares it against each Case value. More efficient than multiple If/ElseIf statements when testing one variable against many values. End each Case's code with Exit: without it, the code carries on into the next Case (falls through). Must be closed with EndSelect.

Example

Example.bam
Select day
    Case 1
        Print "Monday"
        Exit
    Case 6, 7
        Print "Weekend!"
        Exit
    Default
        Print "Another day"
        Exit
EndSelect

; Without Exit the code falls through: for 1 this prints "one" and then "two"
Select n
    Case 1
        Print "one"
    Case 2
        Print "two"
        Exit
EndSelect