The FOR 7 STEP Structure

The syntax for this structure is

«start finish FOR counter loop-clause increment STEP »

FOR … STEP executes the loop-clausesequence just like FOR … NEXT does — except that the program specifies the increment value for counter, rather than incrementing by 1. The loop-clause is always executed at least once.

Syntax

Flowchart

 

Start

1:Start

 

finish

2:finish

 

FOR

counter=start

 

Store finish

 

 

 

loop-clause

Body of loop

 

increment

1:increment

 

 

counter = counter +

 

 

increment

 

STEP

 

 

 

Is

yes

 

counter finish?

 

 

 

no

 

 

FOR 7 STEP Structure

 

FOR takes start and finish from the stack as the beginning and ending values for the loop counter, then creates the local variable counter as a loop counter. Next, the loop-clause is executed — counter can appear within the loop-clause. STEP takes the increment value from the stack and increments 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 the increment is positive, the loop is executed again if counter is less than or equal to finish. If the increment is negative, the loop is executed if counter is greater than or equal to finish. Otherwise, counter is purged and execution resumes following STEP. In the previous flowchart, the increment value is positive.

To enter FOR 7 STEP in a program:

Press !°%BRCH% …%FOR%.

Example: The following program places the squares of the integers 1, 3, 5, 7, and 9 on the stack:

« 1 9 FOR x x SQ 2 STEP »

RPL Programming 1-21