beautypg.com

Program loops, The start construct – HP 48gII User Manual

Page 702

background image

Page 21-53

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.,

=

=

n

k

k

S

0

2


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.

Commands involved in the START construct are available through:

This manual is related to the following products: