If
Usage
• 如果计算condition为True,则If[condition, t, f]给出 t ,如果为False,则给出 f 。
• 如果计算condition既不是True也不是False,则If[condition, t, f ,u]给出 u 。
Notes
• If 仅计算由条件值决定的自变量。 • 如果计算condition既不是True也不是False,If[condition, t, f]不进行计算。 • 如果计算condition为False,If[condition, t] 给出Null。
Further Examples
The test gives False, so y is returned.
In[1]:=
|
Out[1]=
|
The test gives neither True nor False, so neither branch is evaluated.
In[2]:=
|
Out[2]=
|
If there is a fourth argument to If, it is used when the test does not yield True or False.
In[3]:=
|
Out[3]=
|
|