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

4- 132
40 CASE 1 TO 10 !1 <= A+B <= 10
41 PRINT "1 thru 10"
42 GOSUB Routine1
50 CASE 10 TO 20 EXCLUSIVE !10 < A+B < 20
51 PRINT "Between 10 & 20"
52 GOSUB Routine2
60 CASE 20,22,24 !A+B = 20, 22, or 24
61 PRINT "Special Case #1"
62 GOSUB Spec_case1
70 CASE 21,23,25 !A+B = 21, 23, or 25
72 PRINT "Special Case #2"
73 GOSUB Spec_case2
80 CASE > 30 !A+B > 30
81 PRINT "Over 30 by:"
82 PRINT (A+B)-30
83 STOP
90 CASE ELSE !26 <= A+B <= 30
91 PRINT "26 thru 30"
92 GOSUB Routine3
100 END SELECT
SELECT constructs can be nested.
100 SELECT Color1$ !Start outer construct
110 CASE "red", "blue", "yellow" !First case in outer construct
120 GOSUB Primary
130 SELECT Color1$ !Start first inner construct
140 CASE "red" !Case in first inner construct
150 PRINT "RED"
160 PRINT "ORANGE,PURPLE"
170 CASE "blue" !Case in first inner construct
180 PRINT "BLUE"
190 PRINT "PURPLE,GREEN"
200 CASE "yellow" !Case in first inner construct
210 PRINT "YELLOW"
220 PRINT "ORANGE,GREEN"
230 END SELECT !End first inner construct
240 CASE "green","purple","orange" !Second case in outer construct
250 GOSUB Secondary
260 SELECT Color2$ !Start second inner construct
270 CASE "green" !Case in second inner construct
280 PRINT "YELLOW+BLUE"
290 CASE "purple" !Case in second inner construct
300 PRINT "BLUE+RED"
310 CASE "orange" !Case in second inner construct
320 PRINT "RED+YELLOW"
330 END SELECT !End second inner construct
340 END SELECT !End outer construct
Entering the middle of a SELECT construct from a statement other than the
SELECT statement is considered to be a bad programming practice, and is
not recommended. However, if control is transferred to a statement that
is in the middle of a SELECT construct, execution proceeds in line number
order starting with that statement. When a CASE, CASE ELSE, or END
SELECT statement is reached, control is transferred to the statement
following the END SELECT statement.
Control can be transferred out of a SELECT construct and then back by
using a GOSUB or CALL statement.
100 SELECT T
110 REM Clause 1
120 CASE < 0
121 CALL Sub1 !Jump out of SELECT construct
122 PRINT T !Return to construct from 520
130 REM Clause 2
131 CASE 0
132 GOSUB 300 !Jump out of construct