Checks if the given parameter matches any case. If so, the code block of that case will be executed. After that the switch ends so no further cases will be checked.
If a case has no code block the code of the next case will automatically be executed, making it possible to formulate a logical "or" for cases which would otherwise contain the exact same code (see Example 2).
The default block will be executed only if no case matches, no matter its position inside the code block. It is not a case, and will never be entered by fallthrough.
if no default block is provided and no case is matched, the switch block returns the default value true, otherwise it returns what the valid case block returns.
switch (_condition) do
{
case"string1";
case"string2": { hint"string1 or string2" };
case"string3";
case"string4": { hint"string3 or string4" };
case"string5"; // will never enter default's codedefault { hint"default" };
};
Be careful of the parentheses around the variable you're switching on.
If you accidentally use braces instead (e.g: switch { _myVar } do { /*... */ }), it won't error, but will always return default.
It's possible to use Boolean value as a switch and Code as case. One thing to take special care in such case is that code must be in parentheses. Example: