In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch
statement is for.
a = 5;
switch a do
case 1:
case 4:
"case23";
endc
case 0:
"case false";
endc
ends
// output nothing
a = 5;
switch a do
case 5:
"case true";
endc
ends
// output "case true"
a = 5;
switch a do
case "5":
"case true";
endc
ends
// output "case true"
a = false;
switch a do
case 1:
"case true";
endc
default:
"case default";
endc
ends
// output "case default"
a = "pierre";
switch a do
casere "ie": // regular expression comparison
"match ie";
endc
default:
"case default";
endc
ends
// output "match ie"
a = "pierre";
switch a do
casere "IE":
"match ie";
endc
default:
"case default";
endc
ends
// output "case default"
a = "pierre";
switch a do
casere:i "IE": // case insensitive comparison
"match ie";
endc
default:
"case default";
endc
ends
// output "case default"