Strings - Commodore 128 System Manual

Hide thumbs Also See for 128:
Table of Contents

Advertisement

ln the sample program you just typed, the value of the variable X
remains at 5 throughout. You can put calculations to the right of
the = sign to assign the result to a variable. You can mix text with
constants in a PRINT statement to identify them. Type NEW and
press RETURN to clear the Commodore 128's memory; then try
this program:
10 A = 3*100
20 B = 3*200
30 ?"A IS EQUAL TO "A
40 ?" B IS EQUAL TO "B
Now there are two variables, labeled A and B, in the computer's
memory, containing the numbers 300 and 600 respectively. If,
later in the program, you want to change the value of a variable,
just put another assignment statement in the program. Add these
lines to the program above and RUN it again.
50 A = 900 *30/10
60 B = 9 5 + 3 2 + 128
70 GOTO 30
You'll have to press the STOP key to halt the program.
Now LIST the program and trace the steps taken by the
computer. First, it assigns the value to the right of the = sign in
line 10 to the letter A. It does the same thing in line 20 for the
letter B. Next, it prints the messages in lines 30 and 40 that give
you the values of A and B. Finally, it assigns new values to A and
B in lines 50 and 60. The old values are replaced and cannot be
recovered unless the computer executes lines 10 and 20 again.
When the computer is sent to line 30 to begin printing the values
of A and B again, it prints the new values calculated in lines 50
and 60. Lines 50 and 60 reassign the same values to A and B
and line 70 sends the computer back to line 30. This is called an
endless loop, because lines 30 through 70 are executed over and
over again until you press the RUN/STOP key to halt the
program. Other methods of looping are discussed later in this and
the following two chapters.

Strings

A string is a character or group of characters enclosed in quotes.
These characters are stored in the computer's memory as a
3-24

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

128d

Table of Contents