Previous Topic: The do/while Loop StatementNext Topic: The for/in Loop Statement


The for Loop Statement

The for loop performs a sequence of statements for a specified number of times. The for loop has the following syntax:

for (initialize ; test ; increment)
	statement

The for loop is similar to the while loop except that an initialization and increment is included in the loop syntax. Each iteration of the for loop increases the increment, performs the test, and performs the statement.

For example, given an indexed variable Process.square containing 35 values, you could use the following lines of code to set every value to the square of its index:

for (var i = 0; i < 34; i++)
	Process.square[i] = i * i