I'm mystified by this:
g[a_, b_, c_] :=
Module[{d},
d = If[(b < 1), b, b + 1];
If[a < b, d = 0.];
d*c]
g[a, 20, 40]
840
I expected to see an output involving symbolic argument a !?? Now I change the second If so that d is set as returned by If, rather than by above's If argument statement, and now things work as expected:
g[a_, b_, c_] :=
Module[{d},
d = If[(b < 1), b, b + 1];
d = If[a < b, 0., d];
d*c]
g[a, 20, 40]
40 If[a < 20, 0., d$132874]
Just for a bit more evidence, here is a 3rd casting, which also behaves as expected, although evaluation differs as expected:
g[a_, b_, c_] :=
Module[{},
If[(b < 1), b, b + 1]*If[a < b, 0., 1.]*c]
g[a, 20, 40]
840 If[a < 20, 0., 1.]
How does one explain the result of the first expression form?
I expected to see an output involving symbolic argument a !??
why? Also note that sincea
is a symbol, thenIf[a < b, d = 0.]
does nothing since you do not have 3rd argument toIf
. Check the third argument toIf
in help for more info. $\endgroup$