'{$STAMP BS2pe} '{$PBASIC 2.5} ' (c) 2003 Tracy Allen, http://www.emesystems.com ' explores the PBASIC 2.5 commands ' IF - THEN - GOSUB ' and ' IF - THEN - ELSE - ELSEIF - ENDIF ' both single line and multiline variations ' all of these are very consistent passthrough schemes ' ' to use this program as a study guide, ' Enter alternative program cases after #DEFINE below ' then look at tokens using CTRL-M memory map window ' Scroll to the bottom of the window to the red area. #DEFINE example=10 ' 10 IF - THEN - ELSE on single line ' 11 same tokens as 20, multiline with ENDIF ' 12 same tokens as 20 and 21, written in old PBASIC using more labels ' 20 like 20, but include the ELSEIF instruction ' 21 same tokens as 30, but using IF and GOTO in old PBASIC ' 30 IF - THEN - GOSUB ' 31 same tokens as 10, but using GOTOs and labels in old PBASIC #SELECT example ' ---- IF - THEN - ELSE #CASE 10 ' IF-THEN-ELSE construct IF IN1=1 THEN HIGH 0 ELSE LOW 0 END #CASE 11 ' same tokens as 10, single- or multi-line are the same IF IN1=1 THEN HIGH 0 ELSE LOW 0 ENDIF END #CASE 12 ' same tokens as 10,11 IF IN1=1 THEN lab1 GOTO lab2 lab1: HIGH 0 GOTO lab3 lab2: LOW 0 lab3: END ' ---- ELSIF construct #CASE 20 ' include ELSEIF construct x VAR Byte IF x>100 THEN HIGH 0 ELSEIF x=100 THEN HIGH 2 ELSEIF x=99 THEN LOW 2 ELSE ' x<99 LOW 0 LOW 2 LOW 3 ENDIF END #CASE 21 ' same tokens as 30 x VAR Byte IF x>100 THEN lab1 ' if condition GOTO lab2 lab1: ' come here when if condition is true HIGH 0 GOTO lab9 ' done with if condition true lab2: ' come here when if condition is false IF x=100 THEN lab3 ' test 1st elseif condition GOTO lab4 lab3: ' come here when 1st elseif condition is true HIGH 2 ' GOTO lab9 ' done with 1st elseif lab4: ' come here when 1st elseif is false IF x=99 THEN lab5 ' test 2nd elseif GOTO lab6 lab5: ' come here when 2nd elseif condition is true LOW 2 goto lab9 ' done with 2nd elseif lab6: ' come here when second elseif is false LOW 0 ' do these statements when all the others were false LOW 2 LOW 3 lab9: ' last exit point for all conditions END ' ---- IF - THEN - GOSUB #CASE 30 ' pbasic 2.5 IF-THEN-GOSUB construct ' statements A IF IN1=1 THEN GOSUB fubar ' statements C END fubar: ' statements RETURN #CASE 31 ' same tokens as 10, except using old PBASIC ' the if -then-else is parsed, then the gosub ' statements A IF IN1=1 THEN lab1 GOTO lab2 lab1: GOSUB fubar lab2: ' statements C END fubar: ' statements RETURN