Switch/Case/Default
Evaluate a conditional expression and compare for a match.
Switch
The Switch/Case/Default condition expression is evaluated and compared to each case label in turn until a match is found. Subsequent labels will be executed until a break is executed. A default clause will always match. The case expressions do not need to be constants and can be of any type.
Examples
switch($response) {
case "hello":
echo "Hello to you too!";
break;
case "goodbye":
echo "See you later!";
break;
default:
echo "I've no idea what you mean!";
break;
}
Note, the break statement is required to prevent the execution continuing into the next block.
set v=2;
switch($v) {
case 1:
echo "v is 1";
case 2:
echo "v is 2";
default:
echo "v is not 1 or 2";
break;
}
Since there is no break at the end of the case 2 code segment, DMScript will continue to execute the code following the “default” clause:
v is 2
v is not 1 or 2
If this is not desired, make sure you include break.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified August 31, 2024: Signed-off-by: tracyragan <[email protected]> (20379ca)