Creating an Interactive Loop: GOTO, DIM, INPUT Loops tell the computer to go back and repeat instructions in the program automatically. The GOTO command saves you the trouble of typing the same instruction lines over and over again . The DIM and INPUT commands allow you to interact with your computer on a question-and-answer basis. Putting these three commands together- GOTO, DIM , INPUT-lets you have an ongoing conversation with your computer. GOTO: A COMPUTER'S MAP The simplest computer loop is the GOTO loop. GOTO is always followed by a line number that tells the computer where to go on the ne xt command . You need just two commands to create a loop.
Type in the program below to produce an infinite loop: NEW ~~9 PRINT "CONGRATULATIONS! " ~29 GOTO ~~9 RUN To break this infinite loop, turn off the machine or use the I Break I key. When you stop the loop with the I Break I key, one of the following messages appears: STOPPED AT LINE ~~9 or STOPPED AT LINE ~29 The computer is telling you where it was when it received the command to stop. Comma: A Tab Maker The GOTO loop puts out an endless amount of work with just two lines of instruction. To make the program fancier, list your program, position the cursor in the space ne xt to the last quotation mark, insert a comma, and press lR e turnl . Run the program and watch the special effects:
LIST ~~9 PRINT" CONGRATULATIONS! " '" ~29 GOTO ~~9 RUN 4 1