Blitz3D+ Command Reference

Case value[,value2,...]

Parameters

value - a value to compare against the Select expression

value2 (optional) - further values that should run the same branch, comma separated

Description

Starts one branch of a Select block.

The code after a Case runs when the Select expression equals one of its values. Cases are tested in order and only the first match runs - there is no fall-through into the next one, so no break statement is needed.

Listing several values on one Case is how you handle alternatives that share an outcome: Case 1,3,5,7 catches any of them, which saves repeating the same block for every key that should fire the weapon.

Values can be numbers, strings, or Const names - constants make a state machine far more readable than bare numbers.

Case compares for equality, so it cannot express a range on its own. The way round it is to open the block with Select True and write full conditions in each Case, since each is then compared against True: Case hull > 75, Case hull > 40, and so on. That turns Select into a tidy ElseIf ladder, and it also lets a single block test more than one variable.

If nothing matches, Default runs - or nothing does, if there is no Default.

See also: Select, Default, End Select, If, Const.

Example

; Case Example
; ------------

; Grade every possible dice roll
For roll=1 To 6

    Select roll
        ; Each Case runs its block when the Select value matches
        Case 1
            Print "Rolled "+roll+": critical miss - you drop your sword!"
        ; One Case can list several matching values, separated by commas
        Case 2,3,4
            Print "Rolled "+roll+": a plain hit."
        Case 5,6
            Print "Rolled "+roll+": critical hit - double damage!"
    End Select

Next

Print ""
Print "Press any key to close the example"
WaitKey

End

Index