83Plus:Basic:For(
Synopsis
Token Size: 1 byte
Syntax:
- For(Variable,First,Last[,Increment])
- commands
- End
A for loop is used to execute commands while a variable is within a certain range. A for loop starts by setting Variable to First, and running the commands within it. At the end, Variable is incremented by 1 or Increment, if specified. If the value of Variable is greater than Last and Increment is positive, or if the value of Variable is less than Last and Increment is negative, the for loop will stop, and execution will continue after the End statement. Otherwise the commands in the for loop are executed with the new value of Variable.
Comments
The value of Variable may be modified during the for loop, and will have the expected results. Increment may be negative. It cannot be zero.
Note that a for loop is essentially a while loop.
For(X,1,10) Disp X End
could be written as:
1->X While X<=10 Disp X X+1->X End
Use of a Goto statement within a for loop will cause an increase in memory allocation, leading to program slowdowns and eventually a MEMORY error. For example, the following code will eventually cause an error:
Lbl A For(X,1,10) Goto A End
Examples
A for loop is good for looping through a certain range of numbers:
For(X,1,10) Disp X End