HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)
4-: 63
else_clause
Executable program statement or
line_id
. If
num_expr
is
FALSE (zero), the IF THEN ELSE statement executes the
executable program statement or transfers control to
line_id
.
line_id
is the line number or line label to
which control transfers.
Examples
10 IF A=B THEN C=3 !Contains executable statement (C=3)
20 IF X=Y THEN GOTO 40 !Contains executable stmt (GOTO 40)
21 IF X=Y THEN 40 !Contains line identifier (40)
30 IF J<>0 THEN Initialize !Contains line identifier (Initialize)
Lines 20 and 21 above are equivalent.
IF THEN ELSE Construct
The IF THEN ELSE construct is an alternate form of the IF THEN ELSE
statement. The IF THEN, ELSE, and ENDIF keywords define a construct that
executes one statement or set of statements if a numeric expression is
TRUE (nonzero) and another statement or set of statements if that numeric
expression is FALSE (zero).
Syntax
[ELSE ]
[[
else_clause_stmt
]] {ENDIF }
IF
num_expr
THEN [
then_clause_stmt
]...[. ] {END IF}
[. ]
[. ]
Parameters
num_expr
A numeric expression that is considered TRUE if it
evaluates to nonzero; FALSE if it evaluates to zero.
then_clause_
One or more program lines that execute if
num_expr
is
stmt
TRUE. These statements comprise the THEN clause.
else_clause_
One or more program lines that execute if
num_expr
is
stmt
FALSE. These statements comprise the ELSE clause.
After either the IF or ELSE clause executes, control transfers to the
line following the ENDIF statement.
Examples
10 IF I THEN !The IF THEN portion of the construct
20 PRINT "I IS NOT ZERO" !The THEN clause statement
30 ELSE
40 PRINT "I IS ZERO" !The ELSE clause statement
50 ENDIF
20 IF A=B THEN
30 PRINT "A=B" !The THEN clause statements --
40 PRINT A !will execute if A = B
50 ELSE
60 PRINT "A<>B" !The ELSE clause statements --
70 PRINT A,B !will execute if A <> B
90 ENDIF
A statement in the IF or ELSE clause can transfer control out of the IF
THEN ELSE construct.
105 IF (K+J)*I=0 THEN
110 PRINT "OK"
115 GOTO 200 !Control transfers to line 200
120 ELSE