for loop js syntax code example

Example 1: javascript for loop

var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) { 
  console.log(colors[i]);
}

Example 2: javascript for loop

var i;
for (i = 0; i < 10 ; i++) {
  //do something
}

Example 3: java script loop

clear rectangle

Example 4: how to make a javascript for loop

var tops = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144];
for (let i = 0; i < tops.length; i++) {
  document.write(tops[i] + "tops");
}

Example 5: javascript for loop[

for(i=0;i<=5;i++){
  console.log(i);}

Example 6: javascript loops

JS Loops
for (before loop; condition for loop; execute after loop) {
// what to do during the loop
}
for
The most common way to create a loop in Javascript
while
Sets up conditions under which a loop executes
do while
Similar to the while loop, however, it executes at least once and performs a check at the end to
see if the condition is met to execute again
break
Used to stop and exit the cycle at certain conditions
continue
Skip parts of the cycle if certain conditions are met