This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Built-in Functions / Programming / Flow Control  /

  • Which[ , , , , ... ] evaluates each of the in turn, returning the value of the corresponding to the first one that yields True.
  • Example: Which[1==2, x, 1==1, y].
  • Which has attribute HoldAll.
  • If any of the evaluated by Which give neither True nor False, then a Which object containing these remaining elements is returned unevaluated.
  • You can make Which return a "default value" by taking the last to be True.
  • If all the evaluate to False, Which returns Null.
  • See the Mathematica book: Section 2.5.8.
  • See also: Switch, If.

    Further Examples

    Here is a plot of a piecewise-defined function.

    Evaluate the cell to see the graphic.