Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF (EN)

99 540 CLS 550 PRINT "You must follow the temperature with" 560 PRINT "the letter ""C"", ""F"" or ""K"" " 570 PRINT "and nothing else" 580 ENDPROC 590 600 DEF PROCILLEGAL_TEMP 610 CLS 620 PRINT "The temperature you have given is" 630 PRINT "too cold for this universe! Try again" 640 PRINT 650 ENDPROC Obviously the second version is long (about a third longer) but it is much more understandable and this is of crucial importance for medium and large programs. GOTO You may have noticed the use of the GOTO statement in many of the examples above. GOTO is a very useful statement which tells the computer to skip to a particular line number. Beginners in programming find it easy to use.

However, it should be used with care because it can lead to what some people call ‘spaghetti’ programming, a tangle of loops backwards and forwards which makes it very difficult indeed to follow what is going on. The example at the end of chapter 4 shows this in an extreme form. If you are writing short programs then by all means use GOTO . For example, the following program prints out the ASCII code of any key which is pressed – useful if you can’t find an ASCII code chart:

10 PRINT GET 20 GOTO 10 It would be taking things too far to expect people to write 10 REPEAT 20 PRINT GET 30 UNTIL FALSE However, when you write programs of more than, say, 50 lines it is a very good idea to try to use the ‘structure’ provided instead of GOTO statements. It is generally accepted that it is still useful to use GOTO statements as a last resort when handling error conditions. Use whatever techniques make your program (a) work and (b) easy to follow.