Page 21-48
With the cursor
in front of the IF statement prompting the user for the logical
statement that will activate the IF construct when the program is executed.
Example: Type in the following program:
«
→
x
«
IF
‘
x<3
’
THEN
‘
x^2
‘
EVAL END
”
Done
”
MSGBOX
» »
and save it under the name ‘f1’. Press
J
and verify that variable
@@@f1@@@
is
indeed available in your variable menu. Verify the following results:
0
@@@f1@@@
Result: 0
1.2
@@@f1@@@
Result: 1.44
3.5
@@@f1@@@
Result: no action
10
@@@f1@@@
Result: no action
These results confirm the correct operation of the IF…THEN…END construct.
The program, as written, calculates the function f
1
(x) = x
2
, if x < 3 (and not
output otherwise).
The IF…THEN…ELSE…END construct
The IF…THEN…ELSE…END construct permits two alternative program flow
paths based on the truth value of the logical_statement. The general format of
this construct is:
IF
logical_statement
THEN
program_statements_if_true
ELSE
program_statements_if_false
END
.
The operation of this construct is as follows:
1. Evaluate logical_statement.
2. If logical_statement is true, perform program statements_if_true and
continue program flow after the END statement.
3. If logical_statement is false, perform program statements_if_false and
continue program flow after the END statement.
To produce an IF…THEN…ELSE…END construct directly on the stack, use:
„°
@)@BRCH@
‚
@)@IF@@
This will create the following input in the stack:
Содержание 50G
Страница 1: ...HP g graphing calculator user s guide H Edition 1 HP part number F2229AA 90006 ...
Страница 130: ...Page 2 70 The CMDS CoMmanDS menu activated within the Equation Writer i e O L CMDS ...
Страница 177: ...Page 4 10 Function DROITE is found in the command catalog N Using EVAL ANS 1 simplifies the result to ...
Страница 206: ...Page 5 29 LIN LNCOLLECT POWEREXPAND SIMPLIFY ...
Страница 257: ...Page 7 20 ...
Страница 383: ...Page 11 56 Function KER Function MKISOM ...
Страница 715: ...Page 21 68 Whereas using RPL there is no problem when loading this program in algebraic mode ...
Страница 858: ...Page L 5 ...