EasyManuals Logo

Sinclair QL User Manual

Sinclair QL
422 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 #70 background imageLoading...
Page #70 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
fatse.
In
the case
of:
score:::;
7
this
is
obviously correct. Either score equals 7 or
It
doesn't I The expression musf be
true or false - assuming that
it's
not meaningless.
It
may be that
you
do
not
krow
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
REMa
rk
AND
110
PRINT
"Enter
two
vaLues"
\ "1
for
TRUE
or
0
for
FALSE"
120 INPUT
raining,
hate
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
hale_in_roaf
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
FALSE
FALSE
TRUE
TRUE
FALSE
TRUE
FALSE
TRUE
FALSE
FALSE
FALSE
TRUE
effect
DRY
DRY
DRY
WET
54
Rules
for
AND
OR
In
everyday life the word
be'
is
used
In
two
ways.
We
can illustrate the inclusive use of
OR
by thinking of a cricket captain looking
for
players. He might ask "Can you bat or
bowr'" He would be pleased
if
a player could
do
just one thing
well
but he would also
be pleased
if
someone could
do
both.
So
it
is
in
programming: a compound expression
uSing
OR
is
true
if
either or both of the simple statements or variables are
true.
Try
the
following program.
100
REMark
OR
test
110
PRINT
"Enter
two
vaLues"
\
"1
for
TRUE
or
0
for
FALSE"
120
INPUT
"Can
you
bat?",
batsman
130
INPUT
"Can
you
bowl?",
bowLer
140
IF
batsman
OR
bowler
THEN
PRINT
"In
the
team"
12/84

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