![HP 50G User Manual Download Page 710](http://html.mh-extra.com/html/hp/50g/50g_user-manual_156571710.webp)
Page 21-63
The WHILE construct
The general structure of this command is:
WHILE logical_statement REPEAT program_statements END
The WHILE statement will repeat the
program_statements
while
logical_statement
is true (non zero). If not, program control is passed to
the statement right after END. The
program_statements
must include a
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
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
» » »
∑
=
=
n
k
k
S
0
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 ...