evaluates expr, then compares it with each of the formi in turn, evaluating and returning the valuei corresponding to the first match found.


  • Only the valuei corresponding to the first formi that matches expr is evaluated. Each formi is evaluated only when the match is tried.
  • If the last formi is the pattern _, then the corresponding valuei is always returned if this case is reached.
  • If none of the formi match expr, the Switch is returned unevaluated.
  • Switch has attribute HoldRest.
  • You can use Break, Return, and Throw in Switch.


Basic Examples  (2)

Process Boolean value to 1 or 0, giving a message and defaulting to 0 when not Boolean:

Give a suggested symbolic transformation for an expression:

Try the transformation:

Introduced in 1988