Evaluate if one variable has several values oblo Member Posts: 97 Threads: 23 Joined: Jul 2011 Reputation: 0 11-08-2018, 08:08 AM Hi all Instead of... Code:`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: Code:`IF var = (1 OR 2 OR 3 OR 4) THEN` Thanks in advance and cheers britlion Posting Freak Posts: 805 Threads: 135 Joined: Apr 2009 Reputation: 5 11-12-2018, 02:29 PM oblo Wrote:Hi all Instead of... Code:`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: Code:`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. oblo Member Posts: 97 Threads: 23 Joined: Jul 2011 Reputation: 0 11-12-2018, 07:04 PM britlion Wrote:oblo Wrote:Hi all Instead of... Code:`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: Code:`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. Cheers boriel Administrator Posts: 1,733 Threads: 54 Joined: Aug 2019 Reputation: 24 11-12-2018, 11:30 PM In the future there will be constructs for these. Actually ZX Basic will allow dynamic arrays, and you can use a function like "BelongsTo" or "IsIn" (variable, array) to check for it. But not yet. « Next Oldest | Next Newest »