How do I use "if else"?

klz

New Member
Hi,

How do I use "if else"? I can only find "if then".
Or how do i solve this?

change: pause 10
if pin2=0 then change
low out

if b5<3
gosub add_out
else
gosub sub_out
goto seq_1

add_out: b5=b5+1
return

add_out: let b5=1
return


Thank you!!!
 

inglewoodpete

Senior Member
I think you need to have a close look at Manual 2 (Commands) at If...Then / ElseIf...Then / Else / EndIf.

The command structure is like Basic and Visual Basic:
Code:
If [condition1] Then
    [commands1]
ElseIf [condition2] Then
    [commands2]
Else
    [commands3]
EndIf
 

moxhamj

New Member
I'm not quite sure what the code is supposed to be as add_out appears twice as a subroutine (I think the second one is supposed to be sub_out) but correcting that, adding an endif and thinking through the logic of the code where a variable increments and then is reset at a certain value I think this ends up simpler:

change:
pause 10
if pin2=2 then change
low out
if b5<3 then
b5=b5+1
else
b5=1
endif
goto seq_1

Just note that if b5 starts at 0 then whatever b5 is controlling will run 3 times on the first loop and then will run 2 times on loops thereafter if it is reset to 1.
 
Last edited:
Top