77 15 FOR...NEXT This structure makes the computer repeat a number of statements a fixed number of times. Try the following: 10 FOR X = 8 TO 20 20 PRINT X, X+X 30 NEXT X >RUN 8 16 9 18 10 20 11 22 12 24 13 26 14 28 15 30 16 32 17 34 18 36 19 38 20 40 You can see that the computer looped through line 20 with X taking on the value 8, then 9, then 10 etc up to 20. Each time through the loop, X increased by 1. The ‘step size’ can be changed easily. 10 FOR X = 8 TO 20 STEP 2.5 20 PRINT X, X+X 30 NEXT X >RUN 8 16 10.5 21 13 26 15.5 31 18 36 In the two previous examples the value of X (which is called the ‘control variable’) increased each time through the loop.
The ‘control variable’ can be made to decrease by using a negative step size.