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

4-: 131
Each
case_descriptor
must be a numeric literal if
select_expr
evaluates to a numeric value and a string
literal if it evaluates to a string value.
If the
select_expr
value is equal to one of the
specified
case_descriptor
literals or is within the
range specified in the
case_descriptor
, then the case
clause associated with the
case_descriptor
is executed.
stmt
Program line. It is executed if
select_expr
fits the
associated
case_descriptor
. Each sequence of program
lines between a CASE and either the next CASE or an END
SELECT constitutes a case clause.
Examples
100 SELECT Number
110 CASE < 0 !If Number is negative.
120 READ Number
130 CASE 0 !If Number is zero
140 LET Number=Default
150 CASE 1 TO 10 !If Number is 1 - 10
160 PRINT Number
170 GOTO Routine1
180 CASE 10 TO 20 EXCLUSIVE !If Number is 11 - 19 (due to the EXCLUSIVE keyword)
190 PRINT Number
200 Number=2*Number
210 GOSUB Routine2
220 CASE 20,30,40 !If Number is 20, 30 or 40
230 PRINT Number
240 GOSUB 450
250 CASE ELSE !If Number is any other value
260 LET Number=Default
270 END SELECT
HP Business BASIC/XL evaluates the select expression and compares its
value with each case descriptor's starting with the first and proceeding
in line number order, until a case descriptor describes the value or
every case descriptor has been checked.
When a case descriptor describes the value, the statements in its case
clause are executed; then, control is transferred to the statement
following the END SELECT statement. If more than one case descriptor
describes the value, only the first one's case clause is executed.
If no case descriptor describes the value, the CASE ELSE clause is
executed, if there is one. If there is no CASE ELSE clause, control is
transferred to the statement following the END SELECT statement.
The string value of a
select_expr
is compared with the quoted string
literals character by character. The following code segment outputs In
the first half of the dictionary.
100 Str_var$ = "dog"
110 SELECT Str_var$
120 CASE "a" To "m"
130 PRINT "In the first half of the dictionary."
140 CASE "dog"
150 PRINT "my pet."
160 END SELECT
10 SELECT A+B
20 CASE < 0 !A+B < 0
21 PRINT "Negative"
22 STOP
30 CASE 0 !A+B = 0
31 PRINT "Zero"
32 LET X=Default