Commodore PET 2001 Series Introduction Manual page 15

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

Advertisement

Try using the string functions, too. You'll need a new program to do
that (be sure to type in NEW first):
NEW
10 FOR I = 1 TO 10
20 INPUT"ENTER A STRING";A$ 30
PRINT LEN (A$)
40 N E X T I
Lines 10 and 40 you already know about. In Line 30, the new item is
the dollar sign. This tells PET you are entering letters or graphics instead
of numbers. Line 30 prints the function we selected for this example.
Since you know your name best, use your name as the data you INPUT
20.
in line
PET should print the number of letters and spaces in your
name when you RUN the program. PET does count spaces in strings-
even if that's almost the only place it wants them!
Now let's go a step beyond.
First type these lines. Note the comments in italics; they explain
each niece of the program lines.
Line 1 10, 120 and 130 are called "assignment statements", because
they are used to assign values to letters of the alphabet. Line
140
is a PRINT statement and causes PET to print the value of the letter Z.
(PET knows the value of Z because statement 130 told it that Z is
the sum of X and Y.)
Of course, this is a trivial program. You've already learned how to type
`' 5 + 10 and have PET print the answer. But it gets more inter-
esting as we go along.
Now, if you RUN this program, PET will print:
15
You, as the programmer, can put any number you like in statements
1 10 and 120. You don't have to use 5 and 10.
It would be cumbersome to have to retype lines 1 10 and 130 every
time you wanted to change the numbers. So, PET's BASIC allows you to
change the numbers during program execution, using the
INPUT keyword. Let's change the program to show you how to INPUT
data:
100 PRINT "ENTER A NUMBER"
110 INPUT X
115 PRINT "ANOTHER NUMBER"
120 INPUT Y
Since lines 130 and 140 stay the same, we won't retype them. Here,
100
line
prints a message. When you run the program, PET will print
the message so you'll know what you're supposed to do. By using this
"prompt,"
anyone can use your program, because he'll
be told what to do and won't have to guess. Line 1 10 will force PET to
wait until you type in a number and press RETURN.
If you press RETURN without entering any number, PET will think
you don't want to continue running the program. It will jump out of
the program and tell you it's READY for whatever you want it to do
100,
next. Line 115, like line
prints a message prompting you to enter
another number, and line 120 makes PET wait for you to do so.
Now RUN the program.
PET will show:
Type a number-say 23 -and press RETURN. PET prints:
the
c ursor w ill flash here'.
27

Advertisement

Table of Contents
loading

Table of Contents