The 'for' Loop

The for loop is a convenient loop with starting initialization. It is most often used as counting loop. It will take three statements as parameters, each separated by a ';' semicolon. Followed by the code block to be executed:
for([Initialization]; [Condition]; [Incrementation]))
  [Statement to be executed];
It is possible to omit any of the three statements. If there is no condition statement, then the loop will run forever unless it is interrupted from the loop body (i.e. using the break keyword). This is an infinite loop:

Using for as a counting loop

This is the most common use of the for loop. If, for example, you want to print all numbers from 1 to 10, you would write:
for(var i = 1; i <= 10; ++i)
  Log("%d", i);
Notice: the following while loop would do exactly the same:
var i = 1;
while(i <= 10) {
  Log("%d", i);

Using for to iterate over an array

Another function of the for-loop is iterating over arrays. Each element of the array is stored in the variable and the loop body executed for that element. The script looks like this:
for(var element in a)
  Log("%v", element);
This script would output all elements of the array a to the log.

Further examples:

for(var i = 10; i >= 1; i--)
  Log("%d", i);
Counts backwards from 10 to 1.
Peter, 2004-06
G√ľnther, 2010-08