Page 21-51
A complex IF construct like this is called a set of nested IF … THEN … ELSE …
END constructs.
A possible way to evaluate f3(x), based on the nested IF construct shown
above, is to write the program:
« → x « IF ‘x<3‘ THEN ‘x^2‘ ELSE IF ‘x<5‘ THEN ‘1-x‘ ELSE IF
‘x<3*π‘ THEN ‘SIN(x)‘ ELSE IF ‘x<15‘ THEN ‘EXP(x)‘ ELSE –2 END
END END END EVAL » »
Store the program in variable @@@f3@@@ and try the following evaluations:
1.5 @@f3@@@ Result: 2.25 (i.e., x
2
)
2.5 @@@f3@@@ Result: 6.25 (i.e., x
2
)
4.2@@@f3@@@ Result: -3.2 (i.e., 1-x)
5.6 @@@f3@@@ Result -0.631266… (i.e., sin(x), with x in radians)
12 @@@f3@@@ Result: 162754.791419 (i.e., exp(x))
23 @@@f3@@@ Result: -2. (i.e., -2)
The CASE construct
The CASE construct can be used to code several possible program flux paths,
as in the case of the nested IF constructs presented earlier. The general format
of this construct is as follows:
CASE
Logical_statement
1
THEN program_statements
1
END
Logical_statement
2
THEN program_statements
2
END
.
.
.
Logical_statement THEN program_statements END
Default_program_statements (optional)
END
When evaluating this construct, the program tests each of the logical_statements
until it finds one that is true. The program executes the corresponding