Sinclair QL Beginner's Manual page 48

Hide thumbs Also See for QL:
Table of Contents

Advertisement

If the string cannot be converted then an error is reported.
LOGICAL VARIABLES AND SIMPLE PROCEDURES
There is one other type of variable in SuperBASIC, or rather the SuperBASIC system makes it seem
so. Consider the SuperBASIC statement:
IF windy THEN fly_kite
In other BASICs you might write:
IF w=1 THEN GOSUB 300
In this case w=1 is a condition or logical expression which is either true or false. If it is true then a
subroutine starting at line 300 would be executed. This subroutine may deal with kite flying but you
cannot tell from the above line. A careful programmer would write:
IF w=1 THEN GOSUB 300 : REM fly_kite
to make it more readable. But the SuperBASIC statement is readable as it stands. The identifier windy
is interpreted as true or false though it is actually a floating point variable. A value of 1 or any non-
zero value is taken as true. Zero is taken as false. Thus the single word, windy, has the same effect
as a condition of logical expression.
The other word, fly_kite, is a procedure. It does a job similar to, but rather better than, GOSUB 300.
The following program will convey the idea of logical variables and the simplest type of named
procedure.
100 INPUT windy
110 IF windy THEN fly_kite
120 IF NOT windy THEN tidy_shed
130 DEFine PROCedure fly_kite
140 PRINT "See it in the air."
150 END DEFine
160 DEFine PROCedure tidy_shed
170 PRINT "Sort out rubbish."
180 END DEFine
INPUT
OUTPUT
0
Sort out rubbish
1
See it in the air
2
See it in the air
-2
See it in the air
You can see that only zero is taken as meaning false. You would not normally write procedures with
only one action statement, but the program illustrates the idea and syntax in a very simple context.
More is said about procedures later in this chapter.
LET STATEMENTS
In SuperBASIC LET is optional but we use it in this manual so that there will be less chance of
confusion caused by the two possible uses of =. The meanings of = in:
LET count = 3
and in
IF count = 3 THEN EXIT

Advertisement

Table of Contents
loading

Table of Contents