switch statements

index
BASIC

Just as the if statement provides a choice between two blocks of code, based on a boolean value, the switch statement provides a choice between several blocks of code, based on an integer value.

The syntax is fairly complex:

switch (integer_expression) {
    case integer_constant_1:
        statements;
        break;
    case integer_constant_2:
        statements;
        break;
    ...
    case integer_constant_N:
        statements;
        break;
    default:
        statements;
        break;
}

where:

Operation is as follows. The integer_expression is evaluated, then compared against each case in order. When a matching integer_constant is found, execution begins at the following statements, and continues until either a break (or a return) is encountered, or until the end of the switch statement.