Back to index For The for statement repeats a block of instructions one or more times. The number of iterations is controlled by values supplied as arguments. InitVal is the starting value of the for loop. It is often 0 or 1, but it can be any number. InitVal is an expression that establishes the initial value and assigns that value to a variable.
Test is the expression used by the for statement to control the number of iterations of the loop.
As long as the Test expression is true, the loop continues. When the Test expression proves false, the loop ends. Note that unlike all of the other constructs in JavaScript, the for statement uses semicolons, rather than commas, to separate its arguments. Here's an example of a for loop that counts from 1 to 10, stepping one digit at a time. At each iteration, the script inserts some text and begins a new line.