Back to Index

Definition: switch (expr) { case N: { ... } default: { ... } } — Allowed: integer case literals (including negative), optional default; braces required for the switch and each case block.

Evaluates expr as an integer and compares it to each case. Only one default is allowed. Fall-through is supported; use break to exit the switch.

Example

switch (mode) {
  case 0: {
    out(1) = 0;
    break;
  }
  case 1: {
    out(1) = 1;
    break;
  }
  case 2: {
    out(2) = 1;
    // fall-through to default
  }
  default: {
    out(3) = 0;
  }
}