
Page 21-63
loop index that gets modified before the
logical_statement
is checked at
the beginning of the next repetition. Unlike the DO command, if the first
evaluation of logical_statement is false, the loop is never executed.
Example 1 – calculate the summation S using a WHILE…REPEAT…END
construct
The following program calculates the summation
∑
=
=
n
k
k
S
0
2
Using a WHILE…REPEAT…END loop:
«
0.
→
n S
«
WHILE
‘
n
≥
0
‘
REPEAT n SQ S +
‘
S
‘
STO n 1 –
‘
n
‘
STO END S
“
S
”
→
TAG
»
»
Store this program in a variable
@@S4@@
. Verify the following exercises:
J
3
@@@S4@@
Result:
S:14
4
@@@S4@@
Result:
S:30
5
@@@S4@@
Result:
S:55
8
@@@S4@@
Result:
S:204
10
@@@S4@@
Result:
S:385
20
@@@S4@@
Result:
S:2870
30
@@@S4@@
Result:
S:9455
100
@@@S4@@
Result:
S:338350
Example 2 – generate a list using a WHILE…REPEAT…END construct
Type in the following program
«
→
xs xe dx
«
xe xs – dx / ABS 1. + xs
→
n x
«
xs
WHILE
‘
x<xe
‘
REPEAT
‘
x+dx
‘
EVAL DUP
‘
x
‘
STO END n
→
LIST
»
»
»
and store it in variable
@GLIS4
.
•
Check out that the program call 0.5
`
2.5
`
0.5
`
@GLIS4
produces the list {0.5 1. 1.5 2. 2.5}.
•
To see step-by-step operation use the program DBUG for a short list, for
example:
Содержание 49g+
Страница 1: ...hp 49g graphing calculator user s guide H Edition 4 HP part number F2228 90006 ...
Страница 197: ...Page 5 30 LIN LNCOLLECT POWEREXPAND SIMPLIFY ...
Страница 377: ...Page 11 55 Function KER Function MKISOM ...
Страница 457: ...Page 13 26 In the right hand side figure above we are using the line editor to see the series expansion in detail ...
Страница 775: ...Page 26 10 the location of the backup battery in the top compartment at the back of the calculator ...
Страница 838: ...Page L 5 ...