Author Topic: if conditions: 'or' and 'and' = true?  (Read 4819 times)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
if conditions: 'or' and 'and' = true?
« on: February 06, 2011, 09:59:25 AM »
So if you have:
if a == 0 or a == 2 and b < c then

end

What happens then?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: if conditions: 'or' and 'and' = true?
« Reply #1 on: February 06, 2011, 10:02:22 AM »
Unpredictable results.  Best not to mix your "ands" and "ors".

A better way is like this:


Code: [Select]
if a == 0 or a == 2 then
if b < c then
--do stuff
end
end

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: if conditions: 'or' and 'and' = true?
« Reply #2 on: February 06, 2011, 10:04:20 AM »
Unpredictable results.  Best not to mix your "ands" and "ors".

A better way is like this:


Code: [Select]
if a == 0 or a == 2
if b < c then
--do stuff
end
end

Yea, that will correct it hopelyfully, ty :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: if conditions: 'or' and 'and' = true?
« Reply #3 on: February 06, 2011, 10:05:31 AM »
I corrected a typo in the code I posted. :>