1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
1var i; //defines i
2for (i = 0; i < 5; i++) { //starts loop
3 console.log("The Number Is: " + i); //What ever you want
4}; //ends loop
5//Or:
6console.log("The Number Is: " + 0);
7console.log("The Number Is: " + 1);
8console.log("The Number Is: " + 2);
9console.log("The Number Is: " + 3);
10console.log("The Number Is: " + 4);
11//They do the same thing!
12//Hope I helped!
1//for ... in statement
2
3const object = { a: 1, b: 2, c: 3 };
4
5for (const property in object) {
6 console.log(`${property}: ${object[property]}`);
7}
8
9// expected output:
10// "a: 1"
11// "b: 2"
12// "c: 3"
13
1let str = "";
2
3for (let i = 0; i < 9; i++) {
4 str = str + i;
5}
6
7console.log(str);
8// expected output: "012345678"
9
1for (let step = 0; step < 5; step++) {
2 // Runs 5 times, with values of step 0 through 4.
3 console.log(step);
4}
50
61
72
83
94