Page 21-49
Example: Type in the following program:
«
→
x
«
IF
‘
x<3
’
THEN
‘
x^2
‘
ELSE
‘
1-x
’
END EVAL
”
Done
”
MSGBOX
» »
and save it under the name ‘f2’. Press
J
and verify that variable
@@@f2@@@
is
indeed available in your variable menu. Verify the following results:
0
@@@f2@@@
Result: 0
1.2
@@@f2@@@
Result: 1.44
3.5
@@@f2@@@
Result: -2.5
10
@@@f2@@@
Result: -9
These results confirm the correct operation of the IF…THEN…ELSE…END
construct. The program, as written, calculates the function
Nested IF…THEN…ELSE…END constructs
In most computer programming languages where the IF…THEN…ELSE…END
construct is available, the general format used for program presentation is the
following:
IF
logical_statement
THEN
program_statements_if_true
ELSE
program_statements_if_false
END
In designing a calculator program that includes IF constructs, you could start by
writing by hand the pseudo-code for the IF constructs as shown above. For
example, for program
@@@f2@@@
, you could write
Note
: For this particular case, a valid alternative would have been to use an
IFTE function of the form: ‘f2(x) = IFTE(x<3,x^2,1-x)’
⎩
⎨
⎧
−
<
=
otherwise
x
x
if
x
x
f
,
1
3
,
)
(
2
2
Summary of Contents for 50G
Page 1: ...HP g graphing calculator user s guide H Edition 1 HP part number F2229AA 90006 ...
Page 130: ...Page 2 70 The CMDS CoMmanDS menu activated within the Equation Writer i e O L CMDS ...
Page 206: ...Page 5 29 LIN LNCOLLECT POWEREXPAND SIMPLIFY ...
Page 257: ...Page 7 20 ...
Page 383: ...Page 11 56 Function KER Function MKISOM ...
Page 715: ...Page 21 68 Whereas using RPL there is no problem when loading this program in algebraic mode ...
Page 858: ...Page L 5 ...