The implementation of the For-loop
Into the variable (loop counter) we assign a value interval (the begin and end value, e. g. from 0 to 10) for which the specified command will be executed sequentially. This means that the begin value (e. g. 0) is assigned to the counter first and a command (such as a square drawing command) is executed. The counter is then increased by a base value (e. g. 0 is increased to 1) and the command is executed again. This is repeated until the counter does not exceed the end value (in our case it is 10). Then the loop stops and continues to execute the following commands written after the For-loop.
Let´s show the use of the For-loop to draw 10 circles nest to each other (Figure 55):
The value of the variable will increase each loop from the lower limit (in our case 1) to the final limit (in our case 10) and after the program starts, this is displayed (Figure 56):
In addition to numeric coordinates, we added a variable to the circle drawing command (which is also a control variable) because it has a different value at each run of the loop and based on this it secures that the circles will not be drawn at the same place.
However, the For-loop is not limited to one single command. If we want the loop to include more commands, we must close them between the keywords begin and end. We call this program construct a compound command (Figure 57).