for (initialization; comparison; continuation) { instructions... }

 LC  Performs the initialization, then evaluates the comparison and repeats all instructions between the winged brackets as long as the comparison is true resp. non-zero. The continuation statement will be executed after the instructions and before the next repetition. This repetition of instructions is called a loop. Initialization and continuation can be any expression or function call. A for loop is often used to increment a counter for a fixed number of repetitions.



var i;
for (i=0; i<5; i++) // repeat 5 times
	x *= x; // calculate the 5th power of x

See also:

if, while, goto, break, continue, comparisons

► latest version online