GOSUB OF [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
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_ids, or an error occurs if no ELSE
clause is present. Control is transferred to the nth
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"
12 RETURN !Return to line 3
20 REM Subroutine for I=2
21 PRINT "I is two"
22 RETURN !Return to line 3
30 REM Subroutine for I=3
31 PRINT "I is three"
32 RETURN !Return to line 3
40 REM Subroutine for J=1
41 PRINT "J is one"
42 RETURN !Return to line 4
50 REM Subroutine for J=2
51 PRINT "J is two"
52 RETURN !Return to line 4
60 REM Subroutine for J=3
61 PRINT "J is three"
62 RETURN !Return to line 4
90 DATA 3,2
99 END
In the above program, line 2 will be listed as GOSUB I OF 10,20,30.
The ON GOSUB statement works like the GOSUB OF statement. The following
statements are equivalent:
150 ON I GOSUB 10, 20, 30, Quit
150 GOSUB I OF 10, 20, 30, Quit
MPE/iX 5.0 Documentation