BASIC Programming/Beginning BASIC/Control Structures/FOR...NEXT

The FOR...NEXT loop is a form of flow control that places focus on a single counter.

The basic syntax is simple - a variable is given a starting value and ending value, and it increments on each pass of the loop:

A more advanced loop includes the  parameter, which specified the value at which a variable is incremented. It can be negative to have the loop decrease the variable instead of increasing it, and may even be fractional. An example of a reverse counting loop is as follows:

The FOR loop terminates when the variable passes the final value in the loop. This is checked by determining if it is greater than the second parameter (or less than if STEP is negative.)

If desired, you can place variables within the start and end parameters instead of constant numbers.