For Loops
For Statement Loops
The For Statement Loop repeats until a specified condition is FALSE. This is what happens when a for statement loop is running:
The variable (or index) section is executed (i.e.
var i = 1
)This expression usually sets a counter for the loop to run or declare a specific variable.
The conditional section is evaluated (i.e.
i <= 10
)If the value is TRUE, the loop continues to run; when it is FALSE (i.e. > 10), the for statement loop terminates. If the conditional section is omitted, the default is TRUE. Note: omitting the conditional section may lead to an infinite loop. An infinite loop will do just what you think, it will continue on indefinitely. Infinite loops will cause your application to crash, and may even cause your browser to freeze, sometimes forcing you to kill your browser process. It is best to avoid them.
The statement executes (i.e.
console.log('Number:', i);
).The increment section is executed (i.e.
i++
).With this, you can designate if the value is added, subtracted, incremented in 2x, etc.
Last updated