The Case Construct - HP 50g User Manual

Graphing calculator
Hide thumbs Also See for 50g:
Table of Contents

Advertisement

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:
IF 'x<3' THEN 'x^2' ELSE IF 'x<5' THEN '1-x' ELSE IF
«
«
x
'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@@@
2.5 @@@f3@@@
4.2 @@@f3@@@
5.6 @@@f3@@@
12 @@@f3@@@
23 @@@f3@@@

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
Logical_statement
.
.
.
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
Result: 2.25 (i.e., x
Result: 6.25 (i.e., x
Result: -3.2 (i.e., 1-x)
Result
-0.631266... (i.e., sin(x), with x in radians)
Result: 162754.791419 (i.e., exp(x))
Result: -2. (i.e., -2)
THEN program_statements
1
THEN program_statements
2
2
)
2
)
1
2
END
END
Page 21-51

Advertisement

Table of Contents
loading

Table of Contents