Loop structures – HP 48g Graphing Calculator User Manual

Page 418

Attention! The text in this document has been recognized automatically. To view the original document, you can use the "Original mode".

Advertising
background image

Loop structures let a program execute a sequence of commands several

times. To specify in advance horn' many times to repeat the loop, use a

definite loop. To use a test to determine whether or not to repeat the

loop, use an indefinite loop.

START...NEXT

Loop Structures

Enter this structure into a program by pressing fPRG) B K C H

T. Its syntax is;

.start finish

S T F

loop-clause

N E K l

29

START...NEXT executes the loop-clause sequence of commands one
time for each number in the range start to finish. The loop-clause is

alwfa,ys executed at least once.

START takes two numbers {start and finish) from the stack and stores

them as the starting and ending values for a loop counter. Then, the

loop-clause is executed. NEXT increments the counter by 1 and tests
to see if its value is less than or equal to finish. If so, the loop-clause

is executed again—otherwise, execution resumes following NEXT.

START-STEP

Enter this structure into a program by pressing

(PRGl EFiCH

®ST A R T . Its syntax is:

■ s

... .start finish

S T A R T

loop-clause

increment

S T E P ... s -

START...STEP executes the loop-clause sequence just like
START...NEXT does—except that the program specifies the

increment value for the counter, rather than incrementing by 1. The

loop-clause is always executed at least once.

START takes two numbers {start and finish) from the stack and stores
them as the starting and ending values of the loop counter. Then
the loop-clause is executed. STEP takes the increment value from

the stack and increments the counter by that value. If the argument
of STEP is an algebraic or a name, it’s automatically evaluated to a
number.

The increment value can be positive or negative. If it’s positive, the
loop is executed again if the counter is less than or equal to finish. If

29-12 Programming the HP 48

Advertising
This manual is related to the following products: