Rice Code -*- mode: org; -*- Structured programming for portable BASIC. rice <> spaghetti Since support for conditional and iterative blocks other then FOR/NEXT varies among BASIC implementations, code blocks using standard subroutines and IF-THEN statements. Minimize line number dependence. Subroutines have the virtue that their length can change without impacting other code (as long as enough line space is reserved between code segments). * Conditional blocks <line> IF <condition> THEN GOSUB <subr1> <line> IF <condition> THEN GOSUB <subr1> ELSE GOSUB <subr2> All conditionally executed statements in subroutines <subr1>, <subr2>. ** First Generation BASIC <line> IF NOT <condition> THEN <line>+2 <line>+1 GOSUB <subr1> <line>+2 ... <line> IF NOT <condition> THEN <line>+3 <line>+1 GOSUB <subr1> <line>+2 GOTO <line>+4 <line>+3 GOSUB <subr2> <line>+4 ... <line>-1 LET E9=3*<ncase>+<line> <line> IF NOT <cond1> THEN <line>+3 <line>+1 GOSUB <subr1> <line>+2 GOTO E9 <line>+3 IF NOT <cond2> THEN <line>+6 <line>+4 GOSUB <subr2> <line>+5 GOTO E9 <line>+6 ... ... <line>+3*(<ncase>-1) IF NOT <condn> THEN <... (... avoid CASE structures) * Conditional iteration (test before) <line> IF <iterate-condition> THEN GOSUB <subr1> : GOTO <line> (test after) <line>-10 GOSUB <subr1> <line> IF <iterate-condition> THEN GOSUB <subr1> : GOTO <line> ** First Generation BASIC <line> IF <exit-condition> THEN <line>+3 <line>+1 GOSUB <subr1> <line>+2 GOTO <line> <line>+3 ... <line> GOSUB <subr1> <line>+1 IF <repeat-condition> THEN <line> <line>+2 ... * Program layout !bwbasic maximum line number is 32766! - 10- 990: Program identification, documentation - 1000- 5990: Initialization, main program - 6000- 6099: Functions - 6100- 7090: Subroutine 6100 - 7100- 8090: Subroutine 7100 - ... - 29100-30090: Subroutine 29100 - 31000-32766: Data