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  /

  • If[ condition , t , f ] gives t if condition evaluates to True, and f if it evaluates to False.
  • If[ condition , t , f , u ] gives u if condition evaluates to neither True nor False.
  • If evaluates only the argument determined by the value of the condition.
  • If[ condition , t , f ] is left unevaluated if condition evaluates to neither True nor False.
  • If[ condition , t ] gives Null if condition evaluates to False.
  • See the Mathematica book: Section 1.5.6Section 2.5.8.
  • See also: Switch, Which, Condition.
  • Related package: Calculus`DiracDelta`.

    Further Examples

    The test gives False, so y is returned.



    The test gives neither True nor False, so neither branch is evaluated.



    If there is a fourth argument to If, it is used when the test does not yield True or False.