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

Condition


is a pattern which matches only if the evaluation of test yields True.

represents a rule which applies only if the evaluation of test yields True.

is a definition to be used only if test yields True.
  • All pattern variables used in test must also appear in patt.
  • lhs:=Module[{vars}, rhs/;test] allows local variables to be shared between test and rhs. You can use the same construction with Block and With. »
Make a definition with the condition that x should be positive:
Replace all elements which satisfy the condition of being negative:
Make a definition with the condition that x should be positive:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
 
Replace all elements which satisfy the condition of being negative:
In[1]:=
Click for copyable input
Out[1]=
Share a variable between a condition and function body:
Use Condition inside a function body to control evaluation:
New in 1