Sinclair QL Beginner's Manual page 24

Hide thumbs Also See for QL:
Table of Contents

Advertisement

LENGTHS OF STRINGS
SuperBASIC makes it easy to find the length or number of characters of any string. You simply write,
for example:
PRINT LEN(weekday$) 
If the pigeon hole, weekday$, contains FIRST the number 5 will be displayed. You can see the effect
in a simple program:
NEW 
10 LET weekday$ = "FIRST" 
20 PRINT LEN(weekday$) 
RUN 
The screen should display:
5
LEN is a keyword of SuperBASIC
An alternative method of achieving the same result uses both a string pigeon hole and a numeric
pigeon hole.
NEW 
10 LET weekday$ = "FIRST" 
20 LET length = LEN(weekday$) 
30 PRINT length 
RUN 
The screen should display:
5
as before, and two internal pigeon holes contain the values shown:
weekday$
Let us return to the problem of average lengths of words.
Write a program to find the average length of the three words:
FIRST, OF, FEBRUARY
PROGRAM DESIGN
When problems get beyond what you regard as very trivial, it is a good idea to construct a program
design before writing the program itself
1. Store the three words in pigeon holes.
2. Compute the lengths and store them.
3. Compute the average.
4. Print the result.
NEW 
length
FIRST
5

Advertisement

Table of Contents
loading

Table of Contents