Which

Which[test1,value1,test2,value2,]

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

Details

  • 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.

Examples

open allclose all

Basic Examples  (1)

In[1]:=
Click for copyable input
Out[1]=

Scope  (4)

Properties & Relations  (2)

See Also

Switch  If  Piecewise

Tutorials

Introduced in 1988
(1.0)