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 #62 background imageLoading...
Page #62 background image
From
Basic
to
SuperBASIC
(a)
USing
GOSUB
100
LET
coLour
=4 :
background
=2
110
LET
across
=20
120
LET
down =
100
130
LET
side
= 50
140
GOSUB
170
150
PRINT'
END'
160
STOP
170 REMark
Subroutine
to
draw
square
180
PAPER
background:
CLS
190
BLOCK
side,
side,
across,
down,
coLour
200
RETu
rn
(b)
Using a procedure with parameters
100
square
4,
50,
20,
100,
2
110 PRINT 'END'
120
DEFine PROCedure
square<coLour,side,across,down,background)
130
PAPER
background:
CLS
140
BLOCK
side,
side,
across,
down,
coLour
150
END
DEFine
In
the
first
program the values of coloue across, down, Side are fixed by LET statements
before the GOSUB statement activates lines
180
and
190.
Control
is
then sent back
by the RETURN statement.
In
the second program the values are given
in
the
first
line
as
parameters
in
the procedure
call,
square, which activates the procedure and
at
the same time provides the values
It
needs.
In
its
simplest form a procedure has no parameters.
It
merely separates a particular piece
of code, though
even
in
thiS
simpler use the procedure has the advantage over GOSUB
because
it
is
properly named and properly isolated
Into
a self-contained unit.
The power and simplifying effects of procedures are more obvious
as
programs get
larger.
What procedures do,
as
programs get larger
is
not
so
much make programming
easier
as
prevent
It
from getting harder
With
increasing program
size.
The above example
Just
illustrates the
way
they work
in
a simple context.
Examples The
follOWing
examples Indicate the range
of
vocabulary and syntax of SuperBASIC which
has been covered
in
this and earlier chapters, and
will
form a foundation
on
which the
second part of this manual
will
bUild.
The letters of a palindrome are given as single items
in
DATA
statements. The terminating
item
IS
an asterisk and you assume no knowledge of the number of letters
in
the
palindrome READ the letters
into
an
array
and pnnt them backwards. Some palindromes
such
as
'MADAM
I'M
ADAM' only work
If
spaces and punctuation are ignored. The
one used here works properly.
100 REMark
Pa
Li
ndromes
110
DIM
text$(30)
120
LET
textS
=
FILL$
('
',30)
130
LET
count
=30
140 REPeat
get
letters
150
READ
cha--;:acter$
160
IF
characterS
=
'.'
THEN
EXIT
get
Letters
170
LET
count
=
count-1
-
180
LET
text$(countJ
=
characterS
190
END
REPeat
get
Letters
200 PRINT
textS
-
210
DATA
'A','B','L','E'
,'W','A','S'
,'I'
,'E','R'
220
DATA
'E
I
,'I'
,'S','A','W'
,'E','Lt,'B','A','*'
The following program accepts
as
input numbers
in
the range 1
to
3999 and converts
them into the equivalent
In
Roman numerals.
It
does not generate the most elegant form.
It
produces
1111
rather than
IV
46
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