- 29 -
FOR ~ NEXT
Function Executes the statements included from the FOR statement to the NEXT statement
repeatedly while the given conditions are satisfied.
Format FOR <variable> = <initial value> TO <terminal value> [STEP <increment> ]
NEXT [ <variable> [, <variable> ] ···]
Term <initial value>: A numeric value to be set at the beginning of the repetition
An integer or a single-precision real number
<variable>: A variable used as the counter which counts the number of
executions
An integer or a single-precision real number
<increment>: Both positive and negative are available.
<terminal value>: A value for which the repetition is terminated
An integer or a single-precision real number
Explanation An input or assignment to <variable> cannot be performed in the loop, since
<variable> is used as the loop counter. However, <variable> can be used as a value
having the current loop value.
<initial value> is set to <variable> first. When the execution reaches to the NEXT
statement, <increment> specified in STEP is added to/subtracted from the counter
value (<variable>). If STEP is not specified, <increment> is set to +1. A negative
number can also be specified in <increment>. Then, whether or not the counter value
exceeds <terminal value> is checked. If it does not exceed it, the execution is
returned to the next statement of the FOR statement. If it exceeds it, the execution
proceeds to the next statement of the NEXT statement.
For the FOR ~ NEXT statement, the evaluation is made before the execution. In the
following cases, the FOR ~ NEXT statement is not executed once, and the execution
proceeds to the next statement of the NEXT statement.
1) <increment> is positive, and <initial value> is larger than <terminal value>.
Ex.) FOR I=10 to 5 STEP2
2) <increment> is negative, and <initial value> is smaller than <terminal value>.
Ex.) FOR I=1 to 7 STEP-3
When <increment> is 0, the loop is performed endlessly, unless <variable> larger
than <terminal value> is set in the loop.