To avoid an infinite loop, make sure that start_value < end_value.
Example – calculate the summation S using a FOR...NEXT construct
The following program calculates the summation
Using a FOR...NEXT loop:
Store this program in a variable @@S2@@. Verify the following exercises: J
You may have noticed that the program is much simpler than the one stored in
@@@S1@@. There is no need to initialize k, or to increment k within the program. The
program itself takes care of producing such increments.
The FOR...STEP construct
The general form of this statement is:
start_value end_value FOR loop_index program_statements
The start_value, end_value, and increment of the loop index can be positive
or negative quantities. For increment > 0, execution occurs as long as the
index is less than or equal to end_value. For increment < 0, execution
occurs as long as the index is greater than or equal to end_value. Program
statements are executed at least once (e.g.,
0 n FOR k k SQ S + 'S' STO NEXT S "S"
1 0 START 1 1 STEP
TAG " "