Switch Statements

The switch statement is a specialized form of conditional.

For instance, you can write:
switch(intvar*2) {
  case 0: print('case0'); break;
  case 1+1: print('case2'); break;
  default: print('default'); break;
}
          
This statement prints "case0" if the value of intvar*2 is 0, "case2" if the value of intvar*2 is 2, and "default" otherwise. The default is optional. The expression inside the parentheses switch(...) must be of base type, and the expressions following the case keyword must have the same base type.
As in C and Java, the break is needed to skip to the end. For instance, if you leave out the break after the first case, then this statement will print both "case0" and "case2" when intvar*2 is 0:
switch(intvar*2) {
  case 0: print('case0');
  case 1+1: print('case2'); break;
  default: print('default'); break;
}