Line
40
is another
INPUT
statement. This time, however, you are expected to enter a
name instead
of
a number.
The
name which you enter is stored in the variable N$.
This variable, N$, is an example
of
a
"string
variable."
The name that you type, for
example.,
JANICE
SMITH,
is called a
"character
string."
Line
58 calculates the total
of
principal and interest.
Line
60
prints the message
"TOTAL
FOR."
Line
65 prints the name stored
in
N$ followed
by
the word IS, the symbol $, and the
amount
of
the investment.
Line
70
skips a line (PRINTs a blank line).
Line
80 transfers control
back
to line 10.
A
string
is any sequence
of
keyboard characters, for example
JOHN
SMITH
1023 N.
MAIN
STREET
1982
MACROCORP
MARCH
12, 1984
$120.95
In some cases the string may consist entirely
of
digits (e.g. 1982), but it can still be
considered a string as well as a numerical constant.
A
valid
string
variable
is any numeric variable followed by a dollar sign ($). The
following are all valid examples
of
string variables:
N$, A3$,
DA$,
AD$,
ST$
In line
40,
it is essential that the variable
be
a string variable.
If
you tried to use a
numeric variable, the computer would continue to ask for data until a numeric constant
was entered.
The assignment
of
the name to the string variable N$ was made with the
INPUT
statement.
It
is possible to use assignment statements with string variables and
constants
just
as with numeric variables and constants. For example, the following
statement:
11Z11Z1
A$
=
"RADIO
SHACK"
assigns the string
RADIO
SHACK
to the string variable A$. When using an
assignment statement, it is necessary to enclose the string
in
quotes, as shown above.
Each string variable
can
hold up to 256 characters.
If
the total number
of
characters
assigned to string variables exceeds 256, you must set aside additional space. This is
done with the
CLEAR
statement.
For
example, the following line could
be
added to
the program:
5
CLEAR
31Z11Z1
This particular instruction allocates space for
300
characters.
If
you attempt to store
more than
300
characters
in
N$,
an error will result and the program will terminate.
When the Computer is turned
on,
space for 256 characters is allocated automatically.
40