A Simple Loop-The Goto Statement - Commodore 128 System Manual

Table of Contents

Advertisement

—To see from line N1 to line N2 inclusive, type LIST N1 -N2
and press RETURN.
A Simple Loop—The GOTO Statement
The line numbers in a program have another purpose besides
putting 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
program 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. You can number such added lines by fives (15,
25 ...), or 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 PFTUBN IThe 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
3-17

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

128d

Table of Contents