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


gives t if condition evaluates to True, and f if it evaluates to False.
gives u if condition evaluates to neither True nor False.
  • If evaluates only the argument determined by the value of the condition.
  • If is left unevaluated if condition evaluates to neither True nor False.
If the condition is neither True nor False, If remains unevaluated:
The form with an explicit case for an undetermined condition evaluates in any case:
Use TrueQ to force the condition to always return a Boolean value:
Define a piecewise function with both If and Round as piecewise elements:
Use PiecewiseExpand to get it into piecewise normal form:
Perform several different symbolic operations:
If can be used as a statement:
It can also be used as an expression returning a value:
Only the branch actually taken is evaluated:
Define a function by cases:
Alternatively, use several conditional definitions:
Use Which rather than a nested if-then-elsif chain:
Use PiecewiseExpand to convert If to Piecewise:
New in 1