Wednesday 20 February 2013

Emergency Exit, BASIC

At last, after 6+ weeks, I've been tasked to teach something within my competence . . . I thought.  Instrumentation and Computing (Inst&Comp) is moving on from the measurement of density and the measurement of light to the &Comp part of the course.  The class is this Friday, so today the course leader gave me a hand-out and said that QuickBasic was loaded on all the computers in the Physics Lab and I should be okay if I just followed the protocol.  I'm not a total nerd, but I've been around since before the Sinclair ZX80 and have, at various times, learned Fortran, PL/1, Basic, Pascal, C, and Perl: some by formal course and some by seat-of-pants.  As it happens all the formal course languages quickly disappeared from view because I didn't need to use them in and immediately after the course.

First BASIC program in the &Comp manual:
CLS                                 (which  CLears the Screen)
PRINT "YOUR NAME"

which I promptly modified to the more standard:
CLS
PRINT "HELLO WORLD"

So far so good (as the man said when passing the 17th floor having fallen from the top of the Sears Tower).  As I say, I've learned BASIC, I've written programs in BASIC, heck, I've written games in BASIC - although you can't write very exciting games in 1K of memory on a ZX80.  So I thought I'd add a wee loop to my gem, and dug deep to recall how that was done in BASIC :
CLS 
10 PRINT "HELLO WORLD"
GOTO 10

This started printing HELLO WORLD again and  again and  again and  again until the words disappeared off the top of the screen and still kept printing.  Somewhat desperately, I tried to recall how to stop a process in BASIC.
STOP I tried, then EXIT, QUIT, break; <esc>, CTRL-C, CTRL-X, CTRL-Z, q, q!, X, F1, F2, F3 . . . eventually I resorted to the IT Crowd's "have you tried switching it OFF and ON again?" and that stopped its gallop.

GOTO is streng verboten in most 'adult' languages since at least Edsger Dijkstra' famous 1968 letter Go To Statement Considered Harmful and my disastrous short program shows you one reason why.

No comments:

Post a Comment