Shop OBEX P1 Docs P2 Docs Learn Events
How many layer of logic in an IF statement — Parallax Forums

How many layer of logic in an IF statement

CelticLordCelticLord Posts: 50
edited 2014-11-06 16:32 in General Discussion
when performing an IF statement, how many layers of logic can I use in the same IF.
Example.....
if x==1 or x==3 or x==5 and y==1
action to preform here
else
action to perform here

The above will notwork for me, I have to use the folowing...................
if x==1 and y==1
action
elseif x==3 and y==1
action
elseif x==5 and y==1
action
else
action

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2014-11-06 08:52
    || is the absolute value operator. You should use or.

    EDIT: You should also use parentheses. So your if statement should be "if (x==1 or x==3 or x==5) and y==1".
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2014-11-06 08:57
    Dave's edit rendered my reply superfluous.
  • CelticLordCelticLord Posts: 50
    edited 2014-11-06 16:32
    sorry thought I typed the or. I am using or in it?
    edited the post.
    Yes it was the Parentheses that were missing. Thankyou Dave and Tom!
    without them it was doing strangeeeee things and I didn't understand why untill now.
Sign In or Register to comment.