EasyManua.ls Logo

Commodore 128D - Page 277

Commodore 128D
427 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...
GOSUB
n
n
GOTO/GOTO
—Call
a
subroutine
from
the
specified
line
number
GOSUB
line
number
This
statement
is
similar
to
the
GOTO
statement,
except
the
Commo
dore
128
returns
from
where
it
came
when
the
subroutine
is
finished.
When
a
line
with
a
RETURN
statement
is
encountered,
the
program
jumps
back
to
the
statement
immediately
following
the
GOSUB
statement.
The
target
of
a
GOSUB
statement
is
called
a
subroutine.
A
subrou
tine
is
useful
if
a
task
is
repeated
several
times
within
a
program.
Instead
of
duplicating
the
section
of
program
over
and
over,
set
up
a
subroutine,
and
GOSUB
to
it
at
the
appropriate
time
in
the
program.
See
also
the
RETURN
statement.
EXAMPLE:
20
GOSUB
800
This
example
calls
the
subroutine
beginning
at
line
800 and
executes
it.
All
subroutines
must
terminate
with
a
RETURN
statement.
800
PRINT
"HI
THERE":
RETURN
—Transfer
program
execution
to
the
specified
line
number
GOTO
line
number
After
a
GOTO
statement
is
encountered
in
a
program,
the
computer
executes
the
statement
specified
by
the
line
number
in
the
GOTO
statement.
When
used
in
direct
mode,
GOTO
executes
(RUNs)
the
program
starting
at
the
specified
line
number
wi
thout
clearing
the
variables.
EXAMPLES:
10
PRINT"COMMODORE"
The
GOTO
in
line
20
makes
line
10
20
GOTO
10
repeat
continuously
until
RUN/STOP
is
pressed.
GOTO
100
Starts
(RUNs)
the
program
starting
at
line
100,
without
clearing
the
variable
storage
area.
269
BASIC
7.0
ENCYCLOPEDIA—Basic
Commands
and
Statements

Table of Contents

Other manuals for Commodore 128D

Related product manuals