AND / OR function with variables

russbow

Senior Member
I want to call a sub routine if a variable is zero OR 5 and another variable is 1

Code:
if b8=0 or b8=5 and flag=0 then gosub count_it
that is if b8=0 and flag=0 then gosub also if b8=5 and flag=0

Also would this work to re-set flag for b8 values of 1,2,3,4 - 6,7,8 or 9

Code:
if b8<>0 and b8<>5 then let flag=0
It passes the syntax but I just don't feel comfortable with it.
 

Technical

Technical Support
Staff member
For anything that is not goto or gosub you should use a multiline structure:

Code:
if b8<>0 and b8<>5 then 
let flag=0
end if
 

nick12ab

Senior Member
For anything that is not goto or gosub you should use a multiline structure:

Code:
if b8<>0 and b8<>5 then 
let flag=0
end if
And anything within a DO : LOOP or an IF statement should be indented. If there's labels in use, it also looks neater if everything is indented.
Code:
main:
    if b8<>0 and b8<>5 then
        let flag=0
    end if
 

russbow

Senior Member
Thank you both.

It is
Code:
if b8=0 or b8=5 and flag=0 then gosub count_it
that I need reassurance with.

Does this equate to

Code:
if b8-0 and flag=0 then gosub
if b8=5 and flag-0 then gosub
I can read this as
if (b8-0) OR ( b8=5 and flag=0 )
 

MPep

Senior Member
And anything within a DO : LOOP or an IF statement should be indented. If there's labels in use, it also looks neater if everything is indented.
Code:
main:
    if b8<>0 and b8<>5 then
        let flag=0
    end if
Not necessarily, but certainly aids in readability. More experienced programmers WILL use this because it makes fault finding easier. :)
 
Top