evaluates each of the testi in turn, returning the value of the valuei corresponding to the first one that yields True.


  • Which has attribute HoldAll.
  • If any of the testi 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 testi to be True.
  • If all the testi evaluate to False, Which returns Null.


open allclose all

Basic Examples  (1)

Scope  (4)

Programming Behavior  (3)

Which can be maintained in symbolic form:

Conditions are evaluated until one is found that is neither True nor False:

Use True for an else clause that always matches:

Symbolic Transformations  (1)

Define a piecewise function:

Expand it to use Piecewise:

Do symbolic operations:

Properties & Relations  (2)

Use Which rather than a nested if-then-elseif chain:

Use PiecewiseExpand to convert Which to Piecewise:

Introduced in 1988