Hosting Solutions
mobile_logo Table of Contents


The for statement is a loop mechanism that will execute code as long as the condition evaluation continues to be true. It stops running when the condition returns false.

Syntaxfor ( iteration_var; condition; increment/decrement ){ // execute code }

Three parameters inside of its parenthesis: 1. Create the numeric iteration variable(usually named "i"). 2. Establish the condition to evaluate each pass of the loop. 3. Increment(++) or decrement(--) the variable each pass of the loop.

for (var i = 0; i < 5; i++){ document.write("Pass index "+i+" of the loop <br>"); } var array = ["a","b","c","d","e"]; for (var i = 0; i < array.length; i++){ document.write( array[i] + "<br>" ); }



breakconstcontinuedo whileforfor inif elselabelreturnswitchtry catchvarwhilewith