EasyManua.ls Logo

Commodore 128 - Variables

Commodore 128
448 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
10 PRINT 3
No matter how many times you execute this line, the answer will
always be 3.
Variables
Variables are values that can change over the course of an
equation or program statement. There is a part of the computers
BASIC memory that is reserved for the characters (numbers,
letters and symbols) you use in your program. Think of this
memory as a number of storage compartments in the computer
that store information about your program; this part of the
computer’s memory is referred to as variable storage. Type in this
program:
10 X=5
20 ?X
Now RUN the program and see how the computer prints a 5 on
your screen. You told the computer in line 10 that the letter X will
represent the number 5 for the remainder of the program. The
letter X is called a variable, because the value of X varies
depending on the value to the right of the equals sign. We call
this an assignment statement because now there is a storage
compartment labeled X in the computer’s memory, and the
number 5 has been assigned to it. The = sign tells the computer
that whatever comes to the right of it will be assigned to a storage
compartment (a memory location) labeled with the letter X to the
left of the equals sign.
The variable name on the left side of the = sign can be either one
or two letters, or one letter and one number (the letter MUST
come first). The names can be longer, but the computer only
looks at the first two characters. This means the names PA and
PART would refer to the same storage compartment. Also, the
words used for BASIC commands (LOAD, RUN, LIST, etc.) or
functions (INT, ABS, SQR, etc.) cannot be used as names in your
programs. Refer to the BASIC Encyclopaedia in Chapter 5 if you
have any questions about whether a variable name is a BASIC
keyword. Notice that the = in assignment statements is not the
same as the mathematical symbol meaning equals , but rather
means allocate a variable (storage compartment) and assign a
value to it.
3-23

Table of Contents

Other manuals for Commodore 128

Related product manuals