Default

Parameters

None.

Description

Starts the branch that runs when no Case in a Select block matched.

Default is to Select what Else is to If. It takes no values, and everything from it up to End Select runs when none of the Case branches matched. It goes last in the block.

A Select does not need one - without a Default, an unmatched value simply falls out of the block and nothing happens. That is fine when you genuinely only care about a few values.

It is worth adding one anyway in a state machine or a message dispatcher. Putting a Print or a RuntimeError in the Default branch turns "the game silently does nothing" into an obvious message the moment an unexpected value turns up, which is far easier to debug than a screen that just froze.

It is also the natural home for sensible fallback behaviour: an unknown tile type drawn as a placeholder, an unrecognised command answered with a help message.

See also: Select, Case, End Select, Else.

Example

; Default Example
; ---------------

; Inspect each weapon slot - only slots 1 and 2 have a weapon fitted
For slot=1 To 4

    Print "Weapon slot "+slot+":"

    Select slot
        Case 1
            Print "    Laser - rapid fire, low damage"
        Case 2
            Print "    Missile - slow but devastating"
        ; Default runs when no Case above matched the Select value
        Default
            Print "    Empty - nothing equipped"
    End Select

Next

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

End

Index