Shop OBEX P1 Docs P2 Docs Learn Events
TIP: How to emulate "AND" and "OR" in "IF" statements — Parallax Forums

TIP: How to emulate "AND" and "OR" in "IF" statements

BeanBean Posts: 8,129
edited 2006-07-16 03:37 in General Discussion
Okay so SX/B doesn't have compound IF conditions.

Emulating "AND" is not hard at all. Simply use:

  ' Emulate IF (a=1) AND (b=2) THEN
  IF a = 1 THEN
    IF b = 2 THEN
      ' CODE HERE RUNS IF a=1 AND b=2
    ENDIF
  ENDIF

 

But "OR" is a little bit harder, but here is how to do it without needing any additional variables:
 
  ' Emulate IF (a=1) OR (b=2) THEN
  DO
    IF a <> 1 THEN  ' Use Opposite Condition Here
      IF b <> 2 THEN EXIT 'Use Opposite Condition Here
    ENDIF
    ' CODE HERE RUNS IF a=1 OR b=2
  LOOP UNTIL a = a ' Use A Condition that is always true
 


Bean.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com

Low power SD Data Logger www.sddatalogger.com

"I'm a man, but I can change, if I have to, I guess" The Red Green Show
·
Sign In or Register to comment.