If statment... how can I make this work...

Krafter

Member
In other languages it could do the following.

if (this1 = 0 and this2 = 1 and this3 = 0) or that1 = 1 then
do something​
end if
I tried to do this for a picaxe but I can't use "()" so the code fails when "that1" is equal to 1. How can I do if and/or statements?

snippet from the actual code I'm running.

Code:
#picaxe 20m2

symbol redOut    = c.5
symbol grnOut    = c.3
symbol bluOut    = c.2

symbol dip4      = Pinc.0
symbol dip3      = Pinc.1
symbol dip2      = Pinc.4
symbol dip1      = Pinc.6

symbol cnt       = b0
symbol last      = b1
symbol nxt       = b2
symbol stage     = b3
symbol phase     = b4
symbol phaselast = b5

symbol rndm      = w10
symbol bright    = w11
symbol bright2   = w12
symbol rndmphase = w10

initialize:
setfreq m8

main:

do until stage <> last[INDENT]    random rndm
    stage = rndm // 7 + 1[/INDENT]
loop
    last = stage

if dip1 = 1 then[INDENT]    do until phase <> phaselast[INDENT]        random rndmphase
        phase = rndmphase // 3 + 1[/INDENT]
    loop
    phaselast = phase[/INDENT]
end if

if dip2 = 1 and dip3 = 0 and dip4 = 0 or phase = 1 then[INDENT]    select case stage
    
    case = 1[INDENT]        gosub red
        pause 5000[/INDENT]
    
    case = 2[INDENT]        gosub green
        pause 5000[/INDENT]
    
    case = 3[INDENT]        gosub blue
        pause 5000
    [/INDENT]
    case = 4[INDENT]        gosub purple
        pause 5000[/INDENT]
    
    case = 5[INDENT]        gosub orange
        pause 5000[/INDENT]
    
    case = 6[INDENT]        gosub yellow
        pause 5000[/INDENT]
    
    case = 7[INDENT]        gosub white
        pause 5000[/INDENT]
    endselect[/INDENT]
    
end if
 
Last edited by a moderator:

erco

Senior Member
One way:

if this1 = 0 and this2 = 1 and this3 = 0 then do X
elseif that1 = 1 then do X
endif
 

lbenson

Senior Member
Another possibility: don't use b0 for your variable, "cnt", but reserve it to use for its bit constituents, bit0-bit7.

Then:
Code:
if this1 = 0 and this2 = 1 and this3 = 0 then : bit0 = 1 : else : bit0 = 0 : endif
if bit0 = 1 or that1 = 1 then
  do something
end if
You should, of course, use "symbol" to give bit0 a meaningful name.
 

Krafter

Member
Okay. I never thought about using elseif. I'll rearrange my code use use more gosubs so I'm not duplicating code.

Thanks for the advice.
 
Top