A Simple Loop-The Goto Statement - Commodore 128D User Manual

Hide thumbs Also See for 128D:
Table of Contents

Advertisement

n
!
I
A Simple Loop—The GOTO Statement
The line numbers in a program have another purpose besides put
ting your commands in the proper order for the computer. They
serve as a reference for the computer in case you want to execute
the command in that line repetitively in your program. You use the
GOTO command to tell the computer to go to a line and execute the
command(s) in it. Now type:
20 GOTO 10
When you press RETURN after typing line 20, you add it to your pro
gram in the computer's memory.
Notice that we numbered the first line 10 and the second line 20. It is
very helpful to number program lines in increments of 10 (that is, 10,
20, 30,40, etc.) in case you want to go back and add lines in
between later on. You can number such added lines by fives (15,25
...) ones (1,2...)—in fact, by any whole number—to keep the lines
in the proper order. (See the RENUMBER and AUTO commands in
the BASIC Encyclopedia.)
Type RUN and press RETURN, and watch the words COMMODORE
128 move down your screen. To stop the message from printing on
the screen, press the RUN/STOP key on the left side of your
keyboard.
The two lines that you have typed make up a simple program that
repeats itself endlessly, because the second line keeps referring the
computer back to the first line. The program will continue indefinitely
unless you stop it or turn off the computer.
Now type LIST I
i. The screen should say:
10 PRINT "COMMODORE 128"
20 GOTO 10
READY
Your program is still in memory. You can RUN it again if you want to.
This is an important difference between PROGRAM mode and
DIRECT mode. Once a command is executed in DIRECT mode, it is
no longer in the computer's memory. Notice that even though you
used the ? symbol for the PRINT statement, your computer has con
verted it into the full command. This happens when you LIST any
command you have abbreviated in a program.
33
USING C128 MODE-Getting Started in BASIC

Advertisement

Table of Contents
loading

Table of Contents