Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Evaluate if one variable has several values
britlion Wrote:
oblo Wrote:Hi all

Instead of...
IF var = 1 OR var = 2 OR var = 3 OR var = 4 THEN

... is there any way to achieve the same in a more efficient way? Something like that:

IF var = (1 OR 2 OR 3 OR 4) THEN

Thanks in advance and cheers

No, unfortunately not. OR joins two boolean expressions, and if you do "1 OR 2" that evaluates to "TRUE OR TRUE" = TRUE which is not what you are looking for.

While in English that might sound sensible, no programming language allows that shortcut with booleans. Some languages allow a switch command to test for multiple IF cases, but it's not available in ZXB.

You need to test (var=1) OR (var=2) to have the right true false values either side of the OR. You might be able to have something like "IF INT ver >0 AND INT var < 5 THEN" if the numbers are in a range, though.

Thanks for the clarification. I was looking for a more efficient way to check several non-consecutive values, but if there is no other way, I'll have to use the 'old' way.


Messages In This Thread

Forum Jump:

Users browsing this thread: 1 Guest(s)