Skip to content

Case

The syntax for a Case statement is:

Case Begin
    Case {Boolean-expression1}
        {statement1}
        Case Break
    Case {Boolean-expression2}
        {statement2}
        Case Break
    Case {Boolean-expression3}
        {statement3}
        Case BreakCase Else
        {else-statement}
Case End

If Boolean-expression1 is True, then statement1 is executed. If Boolean-expression2 is True, then statement2 is executed. If Boolean-expression3 is True, then statement3 is executed. If none of the Boolean-expressions are true, then the else-statement is executed.

The Case statement allows any number of Boolean-expressions and statements to be executed. The Case Else and {else-statement} are optional. If they are not present, execution will continue at the next statement in the program when all the Boolean expressions are False.

It is normal to end each Case with a Case Break command. The Case Break command will immediately halt execution of the Case statement, and program execution will continue at the next statement in the program (following the Case statement). If you do not end each Case with a Case Break, then execution will continue down through all the Cases until a Case Break is executed or the Case statement ends.

An example of a Case statement is:

Case Begin
    Case (sAnimal = "Cat")
        Move ("Meow") To sNoise
        Case Break
    Case (sAnimal = "Dog")
        Move ("Arf") To sNoise
        Case Break
    Case (sAnimal = "Bird")
        Move ("Tweet") To sNoise
        Case Break
    Case Else
        Move ("") To sNoise
Case End