js looping 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: js loop

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

Example 3: javascript loop

let array = ['Item 1', 'Item 2', 'Item 3'];

array.forEach(item => {
	console.log(item); // Logs each 'Item #'
});

Example 4: loop javascript

for(let i = 0; i < arr.length; i++){

}

Example 5: js for loops

let i;
for (i = 0; i < 6; ++i) {
    console.log("Hello"); // print Hello 6 times
}

Example 6: javascript for loop[

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

Tags:

Java Example