I have written a very simple nested If
as follows
atom = be;
If[atom == li,
lim = 5,
If[atom == be,
lim = 3,
If[atom == b,
lim = 2,
If[atom == c,
lim = 1,
If[atom == n,
lim = 0.5,
If[atom == o,
lim = 0.3,
If[atom == f,
lim = 0.1,
If[atom == ne,
lim = 0.05;
]]]]]]]];
atom
lim
but it works for atom=li
namely just for first case, when I set atom=be
for example it doesn't work and returns lim
as unknown variable. What's wrong with it?
Which
instead ofIf
? $\endgroup$atom == li
evaluates tobe == li
which is neitherTrue
orFalse
. The correct approach is to use===
instead of==
on comparison. $\endgroup$atomlim = {li -> 5, be -> 3, b -> 2, c -> 1, n -> 0.5, o -> 0.3, f -> 0.1, ne -> 0.05}; atom = be; atom /. atomlim
$\endgroup$