EasyManua.ls Logo

Apple IIe - Page 74

Apple IIe
320 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...
74
Apple
lie
Users
Handbook
suming.
By
using subroutines, these additional entries
will
be
unnecessary
:-
A
subroutine
can be
defined
as
a program
which
appears
within
another
larger program. The
subroutine
may be executed
as
many times
as
desired.
The
execution
of
subroutines
is
controlled
by
the
GOSUB and
RETURN
statements. The format
for
the
GOSUB statement
is
as
follows.
GOSUB
line
number
The
computer
will
begin execution
of
the
subroutine
beginning
at
the
line
number
indicated. Statements
will
continue
to
be
executed
in
order,
until
a
RETURN
statement
is
encountered.
Upon
execution
of
the
RETURN
statement,
the
1
computer
will
branch
out
of
the
subroutine
back
to
the
first
line
following
the
original GOSUB statement. This
is
illustrated
in
the
following
example.
Illustration 4-5.
BASIC
Program With a Subroutine
10 INPUT"PAY
TO
THE
ORDER OF
";A$
20 INPUT "CHECK
AMOUNT
";X
30
IF
X = 0
THEN
200
40
IF
X < 0
THEN
GOSUB 100
50
IF
X > 1000
THEN
G,OSUB
100
60
IF
(X
>
0)
AND
(X
< 1000)
THEN
PRINT A$,X
70
GOTO
10
{
100
PRINT
"NOT
VALID
A'10UNT"
Subroutine 110 INPUT "TRY AGAIN '\ X
120
RETURN
200 END
Subroutines can
help
the
programmer
organize his program
more
efficiently.
Subroutines also can make
writing
a program
easier.
By
dividing
a lengthy program
into
a
number
of
smaller
subroutines,
the
complexity
of
the
program
will
be reduced.
Individual
subroutines are smaller and
therefore
more
easily
written
. Subroutines are also
more
easily debugged than a
longer
program.

Other manuals for Apple IIe

Related product manuals