Program loops, The start construct, Program loops ,21-53 – HP 50g Graphing Calculator User Manual

Page 700: The start construct ,21-53

Advertising
background image

Page 21-53

5.6

@@f3c@

Result: -0.631266… (i.e., sin(x), with x in radians)

12

@@f3c@

Result: 162754.791419 (i.e., exp(x))

23

@@f3c@

Result

-2. (i.e., -2)

As you can see, f3c produces exactly the same results as f3. The only
difference in the programs is the branching constructs used. For the case of
function f

3

(x), which requires five expressions for its definition, the CASE

construct may be easier to code than a number of nested IF … THEN … ELSE
… END constructs.

Program loops

Program loops are constructs that permit the program the execution of a number
of statements repeatedly. For example, suppose that you want to calculate the
summation of the square of the integer numbers from 0 to n, i.e.,

To calculate this summation all that you have to do is use the ‚½ key
within the equation editor and load the limits and expression for the summation
(examples of summations are presented in Chapters 2 and 13). However, in
order to illustrate the use of programming loops, we will calculate this
summation with our own User RPL codes. There are four different commands
that can be used to code a program loop in User RPL, these are START, FOR,
DO, and WHILE. The commands START and FOR use an index or counter to
determine how many times the loop is executed. The commands DO and
WHILE rely on a logical statement to decide when to terminate a loop
execution. Operation of the loop commands is described in detail in the
following sections.

The START construct

The START construct uses two values of an index to execute a number of
statements repeatedly. There are two versions of the START construct:
START…NEXT and START … STEP. The START…NEXT version is used when the
index increment is equal to 1, and the START…STEP version is used when the
index increment is determined by the user.

=

=

n

k

k

S

0

2

Advertising