Commodore PET 2001 Series Introduction Manual page 16

Hide thumbs Also See for PET 2001 Series:
Table of Contents

Advertisement

Type another number--perhaps I " and press RI l URN. PET will print
the answer 35 and say READY. Your screen should look
l i k e t h i s :
Note that your PET automatically places the line numbers in ascending
order, too.
Using INPUT makes it easier to check the numbers, doesn't it'? Now
you just type RUN, and each time you do so. yon can use different
28
numbers. But it you have 10 pairs of numbers, typing RUN each time
can STILL he tedious!
So, BASIC has two features which allows you to do an operation (in
this case, add a pair of numbers) as many times as you like without
typing RUN. One of these features is the GOTO statement. It forces
PET to GO TO a line you specify. instead of doing whatever it
would normally do. (In this case, PET would normally stop and print
READY when it finishes the sum.) You can do that with this statement:
150 GOTO 100
Now PET will print the sum, then go hack to line 100 and print the "E
NTER A NUMBER" message. Try it. Add up several pairs of numbers.
When you're ready to go on, just press RETURN without having given
PI :T any data (numbers) and it will jump out of your program and alt
patiently for you to tell it what to do next. (You'll see PET's READY
message and the flashing cursor.)
The second feature is called a FOR-NE
perform an operation (or a sequence of operations) FOR as many
times as you like. The word NEXT is the last line of the sequence,
and tells PET that it has completed all the repeatable operations.
Type these lines.
90 FOR I = 1 TO 10
150 NEXT I
In this example. I is called the "index." PET keeps track of the
number of times it performs the sequence of operations (lines
through 140) and keeps the count in the index. You set the index to l in
statement 90 and tell PITT to count to 10. Everytime PET reaches
statement 150 it increments, or adds to, the count, and goes hack to
statement 90. Then PET checks to see if the number in the index is
greater than the number of repeats you wanted. If it is, then PET looks
for something else to do. If the count is less than or equal to the
number of repeats (in this case, 10), it performs the whole sequence
again.
In brief, PET will let you enter a pair of numbers FOR as many times
as you request. And PET will do as much as you ask to each pair of
numbers before going after the NEXT pair.
www.commodore.ca
Free for personal use but you must have written permission to reproduce
X
T loop. It allows PET to
100
29

Advertisement

Table of Contents
loading

Table of Contents