IDENTIFIERS
AND
STRING
VARIABLES
RANDOM
CHARACTERS
SELF
TEST
ON
CHAPTER
4
22
Names of pigeon holes, such
as:
weekday$
word$
month$
phrase$
are called string identifiers. The dollar signs Imply that the pigeon holes are for character
strings. The dollar must always be
at
the end.
Pigeon holes of this kind are called string variables because they contain only character
strings which may vary
as
a program
runs.
The contents of such pigeon holes are called
values.
Thus words
like
'FIRST'
and 'OF'
may be values
of
string variables named weekday$ and +word$.
You
can
use
character codes
(see
Concept Reference
GUide)
to
generate random
letters.
The upper case letters A
to
Z have the codes 65
to
90.
The function CHR$ converts
these codes into
letters.
The following program
will
print a letter
B.
NEW.II
10
LET
Lettereode
;
66."
20
PRINT
CHR$(Lettereode)
..
'
RUN
..
,
The following program
will
generate trios
of
letters
A,
B,
or
C until
the
word CAB
is
spelled
accidentally.
NEW.II
10
REPeat
taxi
20
LET
first$
;
CHR$(RND(65
TO
67))
30
LET
seeond$;
CHR$(RND(65
TO
67))
40
LET
third$;
CHR$(RND(65
TO
67))
50
LET
word$
;
fi
rst$
&
seeond$
&
thi
rd$
60
PRINT 1
word$
1
70
IF
word$;
"CAB"
THEN
EXIT
taxi
80
END
REPeat
taxi
Random characters, like random numbers or random points are useful for learning
to
program.
You
can easily get interesting effects
for
program examples and exercises
Note the effect the 1 . . 1 have
on
the spacing
at
the output
You
can score a maximum of 10 points from the following test Check your score with
the answers
on
page
107.
1.
What
is
a character string?
2.
What
is
the usual abbreviation of the term, character string?
3.
What distinguishes the name of a string variable?
4.
How
do
some people pronounce a word such
as
wordS?
5.
What keyword
is
used
to
find the number
of
characters
in
a string?
6.
What symbol
is
used
to
join two strings?
7.
Spaces can be part of a string. How are the limits of a string defined?
8.
When a statement such
as:
LET meatS = "steak"
is
executed, are the quotes stored?
9.
What function will turn a suitable code number into a letter"
10. How can
you
generate random upper case
letters?
12/84
•
•
•