You have already seen that programs are much more readable if they contain
sensible variable names. Additionally, all the example programs have used
only a single statement per program line. Programs can be written to contain
more than one statement per line, provided the statements are separated by
colons:
10 MODE 135:PRINT "Type any character-- ";:chosen=GET:PRINT CHR$(ch
osen):PRINT "You typed ";CHR$(chosen)
You can imagine that a program with many multi-statement lines like this is
not easy to follow!
The next section deals with the facilities BBC BASIC offers to simplify the
development and modification of programs. So far you have only used programs
made up of a sequence of instructions. The computer can also repeat
instructions, or choose which of several instructions it will obey. All programs
are built up from a combination of the three program structures: sequence,
repetition and choice. The next few sections describe how you can use these
structures in BBC BASIC.
Planning your programming
The programs in the earlier chapters have all been fairly short, but the easiest
way to write more complex programs is to organise them differently.
Look back at the Teddy program on page Cl9. The program consists of a
sequence of instructions which the computer obeys in line-number order. A
longer program might contain several hundred lines, and is simpler to write if it
is broken into small sections known as procedures.
This program shows the use of procedures:
1 REM draw butterfly
10 MODE 130
20 PROCbody
30 PROC Left_wing
40 PROCright_wing
50 END
60 DEFPROCbody
70 GCOL0,2
80 MOVE 600,500
90 MOVE 700,500
100 PLOT 205,640,700
110 ENDPROC
120 DEFPROC Left-wing
130 GCOL 0, 1
140 MOVE 200,200
C 30