[Closed] How "or" "||" Comparison operator ?
Hi,
noob question here, but for some reason I cant get “or” “||” comparisons to work in max script what am I doing wrong here ?
Code test example 01
test001 = undefined
if (test001 != 0 || test001 != undefined) then (print"not equal") else (print"equal")
Code test example 02
test001 = undefined
if (test001 != (0 || undefined)) then (print"not equal") else (print"equal"
)
Thanks
ok I see, thanks, but how would I then write it in max (if “A” is not equal to “B” or “C” then do X else do Y)
(not working)
if (not "A" == "B" or "A" == "C" )then (print"X")else(print"Y")
This is the workaround I have been doing but its not super nice
if ("A" != "B") then
(
if ("A" != "C") then
(
print"X"
)
else
(
print"Y"
)
)
else
(
print"Y"
)
I think you’re looking to use AND, not OR.
print (if (a != b AND a != c) then "not equal" else "equal")
==========================
If you look at this statement:
a != b OR a != c
the output of this condition will always be true as long as b!=c, because A will always be (different than B) or be (different than C), even if it equals ONE of them.
=============================
If you want to use OR, you’ll need to invert it using De Morgan’s Law:
print (if NOT (a == b OR a == c) then "not equal" else "equal")
===================================
this snippet only failed to work because of precedence issues:
if (not "A" == "B" or "A" == "C" )then (print"X")else(print"Y")
NOT has higher precedence than OR, so the expression is evaluated in this order:
((not "A" == "B") or "A" == "C")
You must use parentheses to have the OR evaluate first.