EasyManuals Logo
Home>Atari>Desktop>800

Atari 800 Basic Reference Manual

Atari 800
122 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 #24 background imageLoading...
Page #24 background image
GOSUB (GOS.)
RETURN (RET.)
16
Program Statements
In
Figure
4-1,
the
outer
loop
will
complete
three
passes
(X
= 1
to
3
).
However,
before
this
first
loop
reaches
its NEXT X
statement,
the
program
gives
control
to
the
inner
loop. Note
that
the
NEXT
statement
for
the
inner
loop
must
precede
the
NEXT
statement
for
the
outer
loop.
In
the
example,
the
inner
loop's
number
of
passes
is
determined
by
the
STEP
statement
(STEP
Z).
In
this
case, Z
has
been
defined
as 0,
then
redefined
as Z +
2.
Using
this
data,
the
computer
must
complete
three
passes
through
the
inner
loop
before
returning
to
the
outer
loop.
The
aexp3
in
the
step
statement
could
also
have
been
defined
as
the
numerical
value
2.
The
program
run
is
illustrated
in
Figure
4-2.
OUTEF.:
LOOP
I
t·~t·-IEF.:
LOOF'
I
t-~t-~EF.:
LOOP
I
t-~HEP
LOOP
OUTEP
LOOF'
I
t·~t-lE~:
LOOP
I
t-~t-~EP
LOOP
I
t-~t-~ER
LOOP
OUTEP
LOOP
IHt·4ER
LOOP
I
t·4t-~EF.~
LlJOP
I
t·~HE~~
LOOP
Figure
4-2.
Nested
Loop
Execution
The
return
address
for
the
loops
are
placed
in
a special
group
of
memory
ad-
dresses
referred
to
as
a
stack.
The
information
is
"pushed"
on
the
stack
and
when
used,
the
information
is
"popped"
off
the
stack
(see
POP.)
Format:
GOSUB
lineno
lineno
RETURN
Example:
100
GOSUB
2000
2000 PRINT "SUBROUTINE"
2010 RETURN
A
subroutine*
is a
program
or
routine
used
to
compute
a
certain
value, etc.
It
is
generally
used
when
an
operation
must
be
replaced
several
times
within
a
pro-
gram
sequence
using
the
same
or
different
values.
This
command
allows
the
user
to
"call"
the
subroutine!,
if
necessary.
The
last
line
ofthe
subroutine
must
contain
a RETURN
statement.
The
RETURN
statement
goes
back
to
the
physical
line
following
the
GOSUB
statement.
Like
the
preceding
FOR/NEXT
command,
the
GOSUB/RETURN
command
uses a
stack
for
its
return
address.
If
the
subroutine
is
not
allowed
to
complete
normally;
e.g., a GOTO
lineno
before
a RETURN,
the
GOSUB
address
must
be
"popped"
off
the
stack
(see
POP)
or
it
could
cause
future
errors.
Generally, a
subroutine
can
do
anything
that
can
be
done
in
a
program.
It
is
used
to
save
memory
and
program-entering
time,
and
to
make
programs
easier
to
read
and
debug.

Table of Contents

Other manuals for Atari 800

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Atari 800 and is the answer not in the manual?

Atari 800 Specifications

General IconGeneral
BrandAtari
Model800
CategoryDesktop
LanguageEnglish

Related product manuals