If var1 = (range of values) OR var 2 = ... Syntax?

moorea21

Senior Member
Trying to write:-
If b0 = 1 TO 5 OR b1 = 6 TO 10 OR b2 = 131 TO 136 OR b3 = 212 TO 218 then b4 = "Y": b5 = "2": End If
But the editor gets hung up at the '5'. I'm not sure if I'm also supposed to nest 'OR's in parentheses?
What is the syntax for testing multiple variables for ranges of values? Is there one?
Thanks
 

premelec

Senior Member
I don't know if that syntax is available - I usually go with IF VAR >=X AND VAR <Y THEN type thing... hippy can answer your extended query...
 

moorea21

Senior Member
moorea21, you really do have to read the manual. There is no alternative.

Here's the online link to "IF": http://www.picaxe.com/BASIC-Commands/Program-Flow-Control/if/
Thanks Tex, I had read that, but I sort of don't expect manuals to be absolutely exhaustive sources for everything a command can do, therefore my question about using 'TO'. It may have been something that is permissible but not documented. Turns out not to be, so never mind!
It seems to accept
If b0 >= 1 AND b0 <= 5 OR b1 >= 6 AND b1 <= 10 OR b2 >= 131 AND b2 <= 136 OR b3 >= 212 AND b3 <= 218 then...
As long as 'then' is followed by a label not a variable name.
My question about parentheses still stands though; am I right in saying that the above is not logically equivalent to my original attempt?
 
Last edited:

hippy

Technical Support
Staff member
If b0 >= 1 AND b0 <= 5 OR b1 >= 6 AND b1 <= 10 OR b2 >= 131 AND b2 <= 136 OR b3 >= 212 AND b3 <= 218 then...
Don't mix AND and OR in the same IF statement. That can cause some unexpected behaviour.

Code:
temp = 0
If b0 >=   1 AND b0 <=   5 Then : temp = 1 : End If
If b1 >=   6 AND b1 <=  10 Then : temp = 1 : End If
If b2 >= 131 AND b2 <= 136 Then : temp = 1 : End If
If b3 >= 212 AND b3 <= 218 Then : temp = 1 : End If
If temp = 1 Then ...
Slightly more optimal ...

Code:
temp = 0
If      b0 >=   1 AND b0 <=   5 Then : temp = 1
Else If b1 >=   6 AND b1 <=  10 Then : temp = 1
Else If b2 >= 131 AND b2 <= 136 Then : temp = 1
Else If b3 >= 212 AND b3 <= 218 Then : temp = 1 : End If
If temp = 1 Then ...
But most optimal of all ...

Code:
If b0 >=   1 AND b0 <=   5 Then label
If b1 >=   6 AND b1 <=  10 Then label
If b2 >= 131 AND b2 <= 136 Then label
If b3 >= 212 AND b3 <= 218 Then label
 
Last edited:

moorea21

Senior Member
Okay, thanks. Shame you can't mix 'and' and 'or' statements somehow, it might help on chips with not much memory. The last option looks a little less cumbersome. I'll try that.
 
Top