'{$STAMP BS2pe} '{$PBASIC 2.5} ' (c) 2003 Tracy Allen, http://www.emesystems.com ' explores the PBASIC 2.5 commands ' DO - EXIT - LOOP ' and ' FOR - EXIT - NEXT ' ' 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 DO - EXIT - LOOP in new PBASIC ' 11 same exact tokens as 10 using IF, GOTOs and labels in old PBASIC ' 12 simplified form of 10, with no statements before EXIT ' 13 same tokens as 12, using IF GOTOs and labels in old PBASIC ' 14 same as 13, but optimized (saves 2 GOTOs, 42 bits) ' 20 FOR - EXIT - NEXT in new PBASIC ' 21 same exact tokens as 20 using IF, GOTOs and labels in old PBASIC ' 22 same as 21 but optimized (saves 42 bits) ' 23 a more complicated situation, with statements preceding EXIT ' 24 same as 23, using IF GOTOs and labels in old PBASIC #SELECT EXAMPLE ' ------ DO - EXIT - LOOP #CASE 10 DO ' statements A IF IN1 THEN statements B : EXIT ' statements C LOOP ' statements D, after loop exits END #CASE 11 ' same tokens as case 10 lab1a: ' statements A IF IN1 THEN lab1b GOTO lab1c lab1b: ' statements B GOTO lab1d ' this is the EXIT lab1c: ' statements C GOTO lab1a lab1d: ' statements D, after loop exits END #CASE 12 ' simplified form of 10, with no statements B before the EXIT DO ' statements A IF IN1 THEN EXIT ' simple EXIT stands alone ' statements C LOOP ' statements D, after loop exits END #CASE 13 ' same tokens as case 12, IF-THEN fully parsed lab1a: ' statements A IF IN1 THEN lab1b GOTO lab1c lab1b: ' this is the EXIT part, only a goto GOTO lab1d lab1c: ' statements C GOTO lab1a lab1d: ' statements D, after loop exits END #CASE 14 ' optimized version of 14, saves two GOTOs lab1a: ' statements A IF IN1 THEN lab1d ' exits directly ' statements C goto lab1a: lab1d: ' statements D execute after loop exits END ' ------ FOR - EXIT - NEXT #CASE 20 FOR x=1 to 15 ' statements A IF in1 THEN statements B : EXIT ' statements C NEXT ' statements D execute after loop exits END #CASE 21 ' same tokens as case 20 lab1: FOR x=1 to 15 ' statements A IF IN1 THEN lab1b GOTO lab1c lab1b: ' statements B GOTO lab1d lab1c: ' statements C NEXT lab1d: ' statements D exectute after loop exits END #CASE 22 ' simplified version of 20, without statements B FOR x=1 to 15 ' statements A IF in1 THEN EXIT ' statements C NEXT ' statements D execute after loop exits END #CASE 23 ' same tokens as case 20 lab1: FOR x=1 to 15 ' statements A IF IN1 THEN lab1b GOTO lab1c lab1b: GOTO lab1d lab1c: ' statements C NEXT lab1d: ' statements D exectute after loop exits END #CASE 24 ' same effect as 23, but more efficient ' short circuits two GOTOs. Saves 42 bits. lab1a: ' statements A IF IN1 THEN lab1d ' directly out of loop if no statements preceed the EXIT ' statements B GOTO lab1a lab1d: ' statements D exectute after loop exits END #ENDSELECT