# HP -28S Manual Page 231

The examples so far have specified an initial counter value of 1, but
any integer is acceptable. Since you're using the counter as a variable,
set the initial and final counter values to the desired initial and final
variable values. The following example puts the third thr,'ugh ninth
square integers on the stack.
3 9 FOR x x SQ NEXT
For another example, see "BDISP (Binary Display)" on page 259 .
. .. increment STEP
The command NEXT always increments the counter by 1. To specify
a different increment, replace NEXT by
n STEP, where n is the desired
increment. STEP is commonly used following FOR
counter, as demon-
strated in the examples below, but it can also be used following
START. The following example puts the
odd square integers from 12
through
52
on the stack.
5 FOR
x x
SQ 2 STEP
The loop clause
::< ::;
Q
2
is executed three times. The command ::;
T E P
first increments the counter from} to 3, then to 5, and then to 7. At
this point the current value of the counter exceeds the final value 5,
so the definite loop structure ends.
The examples so far have used
ascending values of the counter. For
descending values of the counter, you can specify a negative incre-
ment. The following example puts the odd square integers from
52
through
}2
on the stack.
5 1 FOR
x x
SQ -2 STEP
The sequence -2 ::;TEP decrements the counter from 5 to 3, then 1,
and then
-1.
At this point the current value of the counter is less
than the final value
1,
so the definite loop structure ends.
The program "SORT (Sort a List)" on page 270 uses -1 ::;TEP to dec-
rement the counter by one. In this case STEP alters the value of the
counter by
1,
as does NEXT, but the counter decreases rather than
increases.
230
26: Program Structures