const fruits = ["apple", "orange", "banana"]; for (let fruit of fruits) { console.log(fruit); } // => apple // => orange // => banana
const fruits = ["apple", "orange", "banana"]; for (let index in fruits) { console.log(index); } // => 0 // => 1 // => 2
for (let i = 0; i < 2; i += 1) { for (let j = 0; j < 3; j += 1) { console.log(`${i}-${j}`); } }
for (i = 0; i < 10; i++) { if (i === 3) { continue; } text += "The number is " + i + "<br>"; }
for (let i = 0; i < 99; i += 1) { if (i > 5) { break; } console.log(i) } // => 0 1 2 3 4 5
for (let i = 0; i < array.length; i++){ console.log(array[i]); } // => Every item in the array
for (let i = 0; i < 4; i += 1) { console.log(i); }; // => 0, 1, 2, 3
x = 0 i = 0 do { x = x + i; console.log(x) i++; } while (i < 5); // => 0 1 3 6 10
const fruits = ["apple", "orange", "banana"]; for (let i = fruits.length - 1; i >= 0; i--) { console.log(`${i}. ${fruits[i]}`); } // => 2. banana // => 1. orange // => 0. apple
while (condition) { // code block to be executed } let i = 0; while (i < 5) { console.log(i); i++; }