Program Flow. In the format: Line_number command EXAMPLE 1 - NO LOOPS Program: 10 print Hi 20 print J. Output: Hi J. Execution of program by line: 10 20 EXAMPLE 2 - GOTO Program: 10 print Hi 20 print J. 30 GOTO 50 40 print This will not print. 50 print Goodbye! Output: Hi J. Goodbye! Comment: Goto skips around. Execution of program by line: 10 20 30 goto skips to line 50 50 EXAMPLE 3 - IF Program: 10 a = 1 20 IF (a = 1) then 30 { print a is 1 } 40 IF (a = 2) then 50 { print a is 2 } 60 print bye! Output: a is 1 bye! Execution of program by line: 10 20 this criteria is true, do what's in the {}'s 30 40 this criteria is not true, skip the stuff in the brackets 60 Comment: The {}'s go with the if statement and mean to run all code between them if the IF criteria is met. EXAMPLE 4 - CASE Program: Equivalent Program: 10 a = 3 10 a = 3 20 BEGIN CASE a { 30 CASE 1 20 IF ( a = 1 ) 40 { print a = 1 } 30 { print a = 1 } 50 CASE 2 40 IF ( a = 2 ) 60 { print a = 2 } 50 { print a = 2 } 70 CASE 3 60 IF ( a = 3 ) 80 { print a = 3 } 70 { print a = 3 } 90 CASE 4 80 IF ( a = 4 ) 100 { print a = 4 } 90 { print a = 4 } 110 CASE ELSE 100 IF ( a <> 1,2,3,or 4) 120 { print a not 1234 } 110 { print a not 1234 } 130 } END CASE Output: Output: a = 3 a = 3 Comments: Notice that the equivalent program doesn't need line 20 or 130. Lines 30 to 120 are inside the CASE's {}'s so they all go together. Execution of program by line: 10 10 20 variable to check is a 20 a is not 1, skip 30 30 a is not 1, skip 40 40 a is not 2, skip 50 50 a is not 2, skip 60 60 a is 3, do 70 70 a is 3, do 80 70 80 80 a is not 4, skip 90 90 a is not 4, skip 100 100 a is not 1,2,3,or 4, skip 110 110 we matched a, so skip 120 130 EXAMPLE 5 - IF AND {}'S Program: 10 a = 1 20 IF (a = 1) 30 { 40 print a is 1 50 print Woohoo! 60 } 70 IF (a = 2) 80 { 90 print a is 2 100 print it better not be 2 110 } 120 print Done! Output: a is 1 Woohoo! Done! Execution of program by line: 10 20 a is 1, so do lines 30-60 because they are in {}'s 30 40 50 60 70 a is not 2, so skip lines 80-110 because they are in {}'s 120 EXAMPLE 6 - FOR Program: Equivalent Program: 10 print beginning 10 print beginning 20 FOR (a = 0, a < 5, a++) 20 a = 0 30 { 30 print a = \$a 40 print a = \$a 40 print This happens too! 50 print This happens too! 50 if (a < 5) 60 } 60 { goto 30 } 70 print ending 70 print ending Output: Output: beginning beginning a = 0 a = 0 This happens too! This happens too! a = 1 a = 1 This happens too! This happens too! a = 2 a = 2 This happens too! This happens too! a = 3 a = 3 This happens too! This happens too! a = 4 a = 4 This happens too! This happens too! ending ending Comments: a starts at 0, loops until it is no longer less than 5, adding 1 to a at each loop Execution of program by line: 10 20 a starts at 0, a < 5, do lines 30-60 as they are in the for's {}'s 30 40 50 60 end of loop, add 1 to a, goto 20 20 a = 1 < 5, do lines 30-60 30 40 50 60 end of loop, add 1 to a, goto 20 20 a = 2 < 5, do lines 30-60 30 40 50 60 end of loop, add 1 to a, goto 20 20 a = 3 < 5, do lines 30-60 30 40 50 60 end of loop, add 1 to a, goto 20 20 a = 4 < 5, do lines 30-60 30 40 50 60 end of loop, add 1 to a, goto 20 20 a = 5, this is not less than 5, skip lines 30-60 due to {}'s 70 EXAMPLE 7 - WHILE Program: 10 print beginning 20 a = 0 30 WHILE (a < 5) 40 { print a = \$a 50 print This happens too! 60 a = a + 1 } 70 print ending Output: Same as example 6 above. Execution of program by line: 10 20 30 a = 0, if a < 5, do lines 40-60 between the {}'s 40 50 60 end of loop } so goto 30 30 a = 1, if a < 5, do lines 40-60 between the {}'s 40 50 60 end of loop } so goto 30 30 a = 2, if a < 5, do lines 40-60 between the {}'s 40 50 60 end of loop } so goto 30 30 a = 3, if a < 5, do lines 40-60 between the {}'s 40 50 60 end of loop } so goto 30 30 a = 4, if a < 5, do lines 40-60 between the {}'s 40 50 60 end of loop } so goto 30 30 a = 5, a is not < 5, skip lines 40-60 between the {}'s 70 EXAMPLE 8 - NESTED {}'s Program: 10 print beginning 20 for (a = 0, a < 3, a++ ) 30 { 40 print inside for loop 50 if ( a = 1 ) 60 { 70 print a = 1 80 print Woohoo! 90 } 100 print still inside loop 110 } 120 print ending Output: beginning inside for loop still inside loop inside for loop a = 1 Woohoo! still inside loop inside for loop still inside loop ending Comment: Nested {}'s and ()'s all work from the inside-most ones outward. Execution of program by line: 10 20 a = 0, keep going while a < 3, add 1 at end, do lines 30-110 30 40 50 a <> 1, skip lines 60-90 100 110 increment a, goto 20 20 a = 1, keep going, do lines 30-110 30 40 50 a = 1, so do lines 60-90 60 70 80 90 100 110 increment a, goto 20 20 a = 2, which is still < 3, so do lines 30-110 30 40 50 a <> 1, skip lines 60-90 100 110 increment a, goto 20 20 a = 3, a is not < 3, so skip lines 30-110 120