HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)

4-: 91
Syntax
{GOSUB }
ON
num_expr
{GO SUB}
line_id
[,
line_id
]...[ELSE
else_line_id
]
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 to which control
is transferred. The line must be in the same program
unit as the ON GOSUB statement.
else_line_id
Line number or line label of the line to which control
is transferred if the value of
num_expr
is not between
one and the number of
line_ids
specified.
Examples
1 READ I, J
2 ON I GOSUB 10,20,30 !Go to subroutine at line 10, 20, or 30
3 ON J GOSUB 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
The GOSUB OF statement works exactly the same as the ON GOSUB statement.
The following statements are equivalent:
150 ON I GOSUB 10, 20, 30, Quit
150 GOSUB I OF 10, 20, 30, Quit
ON GOTO
The ON GOTO statement transfers control to one of several lines,
depending on the value of a numeric expression. Although the ON GOTO
statement can be input as ON GOTO or ON GO TO, HP Business BASIC/XL
always lists it as ON GOTO.
Syntax
{GOTO }
ON
num_expr
{GO TO}
line_id
[,
line_id
]...[ELSE
else_line_id
]