Which

Which[test1, value1, test2, value2, ...]
evaluates each of the in turn, returning the value of the corresponding to the first one that yields True.

DetailsDetails

  • 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.
New in 1
New to Mathematica? Find your learning path »
Have a question? Ask support »