EasyManuals Logo

Sinclair QL Beginner's Guide

Sinclair QL
135 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #65 background imageLoading...
Page #65 background image
CHAPTER 10 LOGIC
If you have read previous chapters you will probably agree that repetition, decision making and
breaking tasks into sub-tasks are major concepts in problem analysis, program design and encoding
programs. Two of these concepts, repetition and decision making, need logical expressions such as
those in the following program lines:
IF score = 7 THEN EXIT throws
IF suit = 3 THEN PRINT "spades"
The first enables EXIT from a REPeat loop. The second is simply a decision to do something or not. A
mathematical expression evaluates to one of millions of possible numeric values. Similarly a string
expression can evaluate to millions of possible strings of characters. You may find it strange that
logical expressions, for which great importance is claimed, can evaluate to one of only two possible
values: true or false.
In the case of
score = 7
this is obviously correct. Either score equals 7 or it doesn't! The expression must be true or false -
assuming that it's not meaningless. It may be that you do not know the value at some time, but that
will be put right in due course.
You have to be a bit more careful of expressions involving words such as OR, AND, NOT but they are
well worth investigating - indeed, they are essential to good programming. They will become even
more important with the trend towards other kinds of languages based more on precise descriptions
of what you require rather than what the computer must do.
AND
The word AND in SuperBASIC is like the word 'and' in ordinary English. Consider the following
program.
100 REMark AND
110 PRINT "Enter two values" \ "1 for TRUE or 0 for FALSE"
120 INPUT raining, hole_in_roof
130 IF raining AND hole_in_roof THEN PRINT "Get wet"
As in real life, you will only get wet if it is raining and there is a hole in the roof. If one (or both) of the
simple logical variables
raining
hole_in_roof
is false then the compound logical expression
raining AND hole_in_roof
is also false. It takes two true values to make the whole expression true. This can be seen from the
rules below. Only when the compound expression is true do you get wet.
raining
hole_in_roof
raining and hole_in_roof
effect
FALSE
FALSE
TRUE
TRUE
FALSE
TRUE
FALSE
TRUE
FALSE
FALSE
FALSE
TRUE
DRY
DRY
DRY
WET

Other manuals for Sinclair QL

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair QL and is the answer not in the manual?

Sinclair QL Specifications

General IconGeneral
ProcessorMotorola 68008
Clock Speed7.5 MHz
RAM128 KB (expandable to 640 KB)
ROM48 KB
Operating SystemSinclair QDOS
Release Year1984
StorageMicrodrive tape loop
Graphics256x256 pixels, 8 colors
PortsRS-232, ROM cartridge
SoundBeeper (internal speaker)

Related product manuals