EasyManua.ls Logo

Commodore VIC-20 - Page 112

Commodore VIC-20
404 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...
98
The
VIC 20
User
Guide
This statement branches in the same way as a GOTO, but GOSUB
remembers the line number to which it should return. This
is
illustrated in
the following section.
GOSUB
STATEMENT
110
GOSUB
2000
110
\
I
I
Subroutine
)000
I
-start
I
I
2150
RETURN-end
\
\
\
\
\
\
\
\
""
,
'
...
..................
;",'/
#'
\
I
I
,
I
I
/
/
The RETURN statement causes a branch back to the line number that
the GOSUB statement remembered. The three-statement loop
that
initializes array A(I), if converted into a subroutine, would appear as
follows:
113
REM
MAIN
PROGRAM
20
REM
',.'OIJ
eRN
DIMENSION
A
SUBROIJTINE'S
VARIABLE
IN
THE
MAP~
313
REM
PROGRAM.
IT
IS A
GOOD
IDEA
TO
DIMEtJSIOtJ
ALL
'.lARrABLES
50
REM
AT
THE
START
OF
THE
MAIN
PROGRRM.
613
DIM
A(99)
713
OOSUB
2131313
813
REM
DISPLAY
SOMETHING
TO
PROVE
THE
RETUR~1
OCCURRED
913
PRINT"RETURNED"
lee
OOTO
lee
2131313
REM
SUBROUTINE
213113
FOR
1=13
TO
99
213213
A(
1)"1
213313
PRINT
A(
l)
,;
213413
NEXT
I
213513
RETURN

Other manuals for Commodore VIC-20

Related product manuals