HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)
4- 58
When the above program is listed, line 70 will list as GOSUB 90.
The program prints this square:
+----+
| |
| |
+----+
The GOSUB statement is a local subroutine call. The local subroutine is
not a separate program unit (subunit); it belongs to the program unit
that contains it. Parameters cannot be passed to it, but it can access
all variables declared in that program unit.
10 REM Main Program Unit
20 A = 3
30 GOSUB 100
40 PRINT A
50 STOP
100 REM Subroutine
110 A = 1
120 RETURN
999 END
In the above program, line 40 prints 1 (not 3).
GOSUB OF
The GOSUB OF statement is one of the GOSUB corollaries of the ON GOTO and
GOTO OF statements. Control transfers to the selected line, L, by "GOSUB
L" rather than "GOTO L." A RETURN statement returns control to the
statement that follows the GOSUB OF statement. Although the GOSUB OF
statement can be input as GO SUB OF, HP Business BASIC/XL always lists it
as GOSUB OF.
Syntax
{GOSUB } [ {
else_line_id
}]
{GO SUB}
num_expr
OF
line_id
[,
line_id
]... [ELSE {CONTINUE }]
Parameters
num_expr
A numeric expression that is evaluated and converted to
an integer,
n
. The integer
n
must be between one and
the number of
line_id
s, or an error occurs if no ELSE
clause is present. Control is transferred to the
n
th
line_id
.
line_id
Line number or line label of the line that control is
transferred to. The line must be in the same program
unit as the GOSUB OF statement.
else_line_id
Line number or line label of the line that control is
transferred to if the value of
num_expr
is not between 1
and the number of
line_ids
specified.
CONTINUE A keyword used to specify that no branch should be made.
The program continues executing at the next line
Examples
1 READ I, J
2 GOSUB I OF 10,20,30 !Go to subroutine at line 10, 20, or 30
3 GOSUB J OF 40,50,60 ELSE 99 !Go to subroutine at line 40,50, or 60 or to
!line 99
4 STOP !if J < 1 or J > 3
10 REM Subroutine for I=1
11 PRINT "I is one"