Sinclair QL Beginner's Manual page 63

Hide thumbs Also See for QL:
Table of Contents

Advertisement

210 IF suit = 1 THEN PRINT "clubs"
220 IF suit = 2 THEN PRINT "diamonds"
230 IF suit = 3 THEN PRINT "spades"
There are new ideas in this program. They are in line 160. The meaning is clearly that the number is
actually printed only if two logical statements are true. These are:
value is greater than or equal to 2 AND value is less than or equal to 10
Cards outside this range are either aces or 'court cards' and must be treated differently
Note also the use of ! in the PRINT statement to provide a space and ; to ensure that output continues
on the same line.
There are two groups of mathematical functions which we have not discussed here. They are the
trigonometric and logarithmic. You may need the former in organising screen displays. Types of
functions are also fully defined in the reference section.
LOGICAL VARIABLES
Strictly speaking, SuperBASIC does not allow logical variables but it allows you to use other variables
as logical ones. For example you can run the following program:
100 REMark Logical Variable
110 LET hungry = 1
120 IF hungry THEN PRINT "Have a bun"
You expect a logical expression in line 120 but the numeric variable, hungry is there on its own. The
system interprets the value, 1, of hungry as true and the output is:
Have a bun
If line 110 read:
LET hungry = 0
there would be no output. The system interprets zero as false and all other values as true. That is
useful but you can disguise the numeric quality of hungry by writing:
100 REMark Logical Variable
110 LET true = 1 : false = 0
120 LET hungry = true
130 IF hungry THEN PRINT "Have a bun"
STRING VARIABLES
There is much to be said about handling strings and string variables and this is left to a separate
chapter.
PROBLEMS ON CHAPTER 9
1. A rich oil dealer gambles by tossing a coin in the following way. If it comes down heads he gets 1.
If it comes down tails he throws again but the possible reward is doubled. This is repeated so that
the rewards are as shown.
THROW
REWARDS
By simulating the game try to decide what would be a fair initial payment for each such game:
1
2
3
4
5
6
1
2
4
8
16
32
7
64

Advertisement

Table of Contents
loading

Table of Contents