iterating over numbers js code example

Example 1: for of loop syntax javascript

for (let step = 0; step < 5; step++) {
  // Runs 5 times, with values of step 0 through 4.
  console.log('Walking east one step');
}

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!");
  }
}

Tags:

Cpp Example