MQL4 Reference Language Basics Operators Switch Operator
Switch OperatorCompares the expression value with constants in all the case variants and passes control to the operator that corresponds to the expression value. Each variant of case can be marked with an integer constant, a literal constant or a constant expression. The constant expression can't contain variables or function calls. Expression of the switch operator must be of integer type.
Operators marked by the default label are executed if none of the constants in case operators is equal to the expression value. The default variant should not be necessarily declared and should not be necessarily the last one. If none of the constants corresponds to the expression value and the default variant is not available, no actions are executed. The case keyword with a constant are just labels, and if operators are executed for some case variant, the program will further execute the operators of all subsequent variants until the break operator occurs. It allows to bind a sequence of operators with several variants. A constant expression is calculated during compilation. No two constants in one switch operator can have the same value. Examples:
See also Initialization of Variables, Visibility Scope and Lifetime of Variables, Creating and Deleting Objects |