What I am wondering is how do you perform multiple lines when using the If statement. I know the following is not proper Mathematica code, but how would I do this in Mathematica?
if(x<1,
y=2x;
z=2y
else
y=x/2;
z=y/2
)
Mr. Wizard help:
It does work. For example:
In[181]:= x = 0; If[x < 1, y = 2 x; z = 2 y, y = x/2; z = y/2]
Out[181]= 0
Another example:
In[182]:= x = 2; If[x < 1, y = 2 x; z = 2 y, y = x/2; z = y/2]
Out[182]= 1/2
But if the expressions are quite long and complicated, maybe this approach?
In[180]:= x = 2; If[x < 1,
{
y = 2 x;
z = 2 y
},
{
y = x/2;
z = y/2
}
]
Out[180]= {1/2}
If[x < 1, y = 2 x; z = 2 y, y = x/2; z = y/2]??? – Mr.Wizard Jul 01 '15 at 16:47