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 #95 background imageLoading...
Page #95 background image
CHAPTER
14
PROGRAM
STRUCTURE
•
•
In
this chapter
we
go again over the ground of program structure: loops and decisions
or selection.
We
have tried
to
present things
in
as
simple a
way
as
possible but
SuperBASIC
is
designed
to
cope properly with the simple and the complex and
all
levels
in
between. Some parts of this chapter are difficult and
if
you
are new
to
programming
you may wish
to
omit parts . The topics covered are:
Loops
Nested loops
Binary decisions
Multiple decisions
The latter parts of the
first
section,
Loops,
get difficult
as
we
show how Super
BASIC
copes
with problems that other languages simply ignore. Skip these parts
If
you
feel
so
inclined
but the other sections are more straightforward.
In
this section
we
attempt
to
Illustrate the well-known problems
of
handling repetition
LOOPS
with simulations of some Wild
West
scenes. The context may be contrived and trivial
but
it
offers a simple basis for discussion and
it
illustrates difficulties which arise across
the whole range of programming applications.
A bandit
is
holed up
in
the Old School House. The sheriff has
six
bullets
in
his gun EXAMPLE 1
Simulate the
firing
of
the
six
shots.
100
REMark
Western
FOR
Program 1
110
FOR
bul
Lets
=1
TO
6
120
PRINT
"Take
aim"
130
PRINT
!IF;
re
shot"
140
END
FOR
buLLets
•
100
REMark
Western
REPeat
110
LET buL
Lets
= 6
120
REPeat
bandit
130
PRINT
"Take aim"
140
PRINT
"Fire
shot"
150
LET
bullets
=
buLLets-
160
IF
buL
Lets
= 0
THEN
EXIT
170
END
REPeat
bandit
Both these programs produce the same output:
Take
aim
Fi
re
a
shot
Program 2
FOR SERVICE MANUALS
CONTACT:
MAURITRON
TECHNICAL
SERVlCEf
www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844
- 352554
Program 2
is
printed six times.
If,
In
each program the 6
is
changed
to
any number down
to
1 both programs
still
work
as
you
would expect. But what
if
the gun
is
empty before any
shots
have been fired?
Suppose that someone has secretly taken
all
the bullets out of the sheriff's gun. What EXAMPLE 2
happens
if
you simply change the 6
to
0
in
each program?
100
REMark
Western
FOR
Zero
Case Program 1
110
FOR
buLlets
=1
to
0
120
PRINT
"Take aim"
130
PRINT
"Fi
re
a
shot
ll
140
END
FOR
buLLets
This
works correctly. There
is
no
output The zero case behaves properly
in
SuperBASIC
100
REMark
Western
REPeat
Fai
Ls
110
LET
bullets
= 0
120
REPeat
bandit
130
PRINT
"Take
a;m
ll
140
PRINT
"Fi
re
shot"
150
LET
buLLets
=
bullets
- 1
160
IF
buLLets
=0
THEN
EXIT
bandit
170
END
REPeat
bandit
12/84
79

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