FOR¶
Function¶
FOR executes a series of instructions in a loop a given number of times.
Syntax¶
Where N is a variable, A is a numeric start value, B is a numeric end value and C is an increment/decrement value.
A, B and C can be numbers, variables or expressions.
Examples¶
10 FOR A = 1 TO 100 STEP 10
100 NEXT A
causes the value of A to equal 1,11,21 etc., for each execution of the loop.
To obtain a decrementing count negative values of STEP are used.
1000 FOR Z1=91 TO 10 STEP -.1
1050 NEXT Z1
Remarks¶
When followed by a NEXT statement, FOR will execute the intervening parameters for the number of times indicated by the values A and B divided by N to the formula:
(B-A+2)/N
When terminating F0R…NEXT loops it is important to end using NEXT and not GOTO. Alternatively, exiting via a RETURN when in a subroutine will not cause a build up of the ‘control stack’.
Failure to do this will result in a control stack error.