Download STARTUP HANDBOOK

Transcript
18.2.2 GOSUB
Call a subroutine.
Syntax
GOSUB_<*labelname>
Description
To use the same program at different positions in one program describe the process as
a subroutine. The subroutine can be used by calling it from the different positions.
The subroutine must be described in the same file as the calling program.
If a subroutine is called using a GOSUB statement, control moves to the subroutine. If
control executes a RETURN statement on the last line of the subroutine, it returns to
the next line of the program that called the subroutine.
A subroutine can be called from another subroutine, which is called "calling nesting."
Note: Callings can be nested up to 31 times including GALL and GOSUB. For
rules about program label, refer to Section 18.3.1 "GOTO."
Program example 1
Calls same program
many times.
Program example 2
Calls other subroutine from a
subroutine.
Main routine
(Calling routine)
Main routine
(Calling routine)
Subroutine 1
Subroutine 1
Subroutine 2
Example
IF IO[128]=ON THEN GOSUB *Line1
IF I2=5 THEN
GOSUB *Lavel2
END IF
'If IO[128] is ON, jump to the label *Line1:
'If I2 is 5
'jump to the label name <*Label2:>
18-3