javascrupt loops code example

Example 1: js for loop

var i; //defines i
for (i = 0; i < 5; i++) { //starts loop
  console.log("The Number Is: " + i); //What ever you want
}; //ends loop
//Or:
console.log("The Number Is: " + 0);
console.log("The Number Is: " + 1);
console.log("The Number Is: " + 2);
console.log("The Number Is: " + 3);
console.log("The Number Is: " + 4);
//They do the same thing!
//Hope I helped!

Example 2: loops javascript

/*Loops are great tools when you need your program to run a code block a 
certain number of times or until a condition is met, but they need a 
terminal condition that ends the looping. Infinite loops are likely to 
freeze or crash the browser, and cause general program execution mayhem, 
which no one wants.

Infinite loop example(do not call this function!):*/
function loopy() {
  while(true) {
    console.log("Hello, world!");
  }
}

/*Loop example with terminal condition:*/
function myFunc() {
  for (let i = 1; i <= 4; i += 2) {
    console.log("Still going!");
  }
}