Switch-Case

The switch-case conditional statement is an alternative to the if-else statement. It consists of aswitch part, which holds an expression that should evaluate to an integer result, and several case blocks, which define possible integer results and corresponding actions. This statement is more efficient than the if-else statement and should be preferred, if the tested expression returns an integer and there will be multiple branches based on its result.

Note that if there is no
break at the end of a case block, script execution "falls through" to the next case block, as if its value also matched the result of the tested expression.

Notice

There should be no whitespace between the word "default" and the following colon. Also, there should be no other labels with the name "default" within the script.

Values for case comparisons are pre-compiled. Therefore, if an exported variable is used as a constant in such a comparison, and if its value is changed in the C++ code, the old value will be used nevertheless.

It is possible to use typeid(variable_type) as a constant for a case within a switch. This function checks if the variable belongs to a specified type and performs a corresponding action.