if else command

fran1942

New Member
Hello, on my 08M2, looking at the following code:

main:
if pin3 = 1 then
high 1
goto playTunes
else
goto main
endif

Is this syntax correct to perform both the "high 1" and "goto playtunes" commands if pin=3.
Can you perform two things if your logic testing is correct, or do you need to direct it to a seperate function to run those two things ?
(previously I have only ever had to do one thing after a logic test.)

thanks for any help.
 

Svejk

Senior Member
Yes fran, the logic is corect (mine or yours). If condition then execute endif statement will execute everthing inside the statement if the condition is true.
 

westaust55

Moderator
Yes, your logic concept is correct and you can have multiple commands between THEN and ENDIF or between THEN and ELSE and between ELSE and ENDIF.
Without seeing your more complete code it is not possible to verify 100% if the example you have given will perform exactly as you wish.
Here are some other configurations that perform the same as your code example
Code:
main:
if pin3 = 1 then
high 1
goto playTunes
endif
goto main
and:
Code:
main:
if pin3 = 0 then main
high 1
goto playTunes
 

vttom

Senior Member
You might want to ponder the following code, which is functionally equivalent:

Code:
do
loop until pin3 = 1

high 1
goto playTunes
It's a little more clear that this bit of code is simply waiting for pin3 to go high before doing something.
 

premelec

Senior Member
Ah... the poetry of programs - so many ways to say the same thing :) [as long as they give us a good command selection...]
 
Top