EasyManua.ls Logo

AMSTRAD cpc 6128 - Writing a Simple Procedure; Procedures with Parameters

AMSTRAD cpc 6128
520 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Writing
Cl
Simple Procedure
It is easy to visualise
that
ifthe
movements:
fd
60
rt
90
.... were to be
repeated
4 times each, a
square
with
sides of60
units
would be drawn.
The same effect
can
be achieved by writing a simple formula:
repeat
4
[fd
60
rt
90]
Clear
the
screen
and
then
try
typing
this
in
to check
what
happens.
To
make
this
formula into a new procedure called '5 q U
are',
type:
to
square
repeat
4
[fd
60
rt
90]
end
Dr. LOGO will now
understand
'5qua
re',
and
each time
it
encounters the word
'5 q
U
are'
it
will
draw
a
square
on
the
screen. We could have given this procedure
any
name,
but
we chose '5
qu
a r
e'toremind
us
what
it
does.
Dr.
LOGO allows
us
to type
in
a whole
set
of commands together
so
the
instructions:
square
rt
45
square
.... will
draw
two squares,
the
second
at
a 45 degrees angle to
the
first.
Procedures with
parameters
It
is possible to
make
a procedure to which we can say 'how much',
in
the same way
that
we
can
say 'how much' to a built-in procedure.
To
make
a procedure
thatwill
draw squares of different sized sides,
the
definition of' 5 q U
are'
can
be altered
to:
to
squareanysize
:side
repeat
4
[fd
:side
rt
90]
end
You will notice
that
the
variable : 5 i
de
starts
with
a colon. This indicates to Dr.
LOGO
that:
5 i
de
is a variable
rather
than
a command.
When we use
the
procedure 5 q U
are
any
5 ; z
e,
the
variable : 5 ; d e
must
have a
value. Hence
the
instruction 5 q U
are
any
5 ; z e 1
50
would produce a square
with
sides of150 units.
Chapter 6
Page 4 Introduction
to
Logo

Table of Contents

Related product manuals