JavaScript » Statements » For

Syntax:
for ([initial-expression]; [condition]; [increment-expression])
{statements}

The for statement creates a loop consisting of three optional expressions enclosed in brackets and separated by semicolons, and a block of statements to be executed.

The first expression is used to initialise a counter variable, the second (optional) provides a condition that is evaluated on each pass through the loop, and the third updates or increments the counter variable.

Examples

Code:
for(i=0; i<10; i++)
   document.write(i + ".<BR>");
Explanation:

This example simply counts up from zero for as long as the counter is less than 10.