This is documentation for Mathematica 7, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Switch

Switch[expr, form1, value1, form2, value2, ...]
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.
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:
Process Boolean value to 1 or 0, giving a message and defaulting to 0 when not Boolean:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]=
 
Give a suggested symbolic transformation for an expression:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
Try the transformation:
In[3]:=
Click for copyable input
Out[3]=
New in 1