Loops Flashcards
Create a loop that runs from 0 to 9 and logs index I to the console.
var i;
for (1 = 0; i < 10; i++) {
console.log(i);
}
Create a loop that runs through each item in the fruits array, assigns it to an index named x, and logs x to the console.
var fruits = [“Apple”, “Banana”, “Orange”];
for (x in fruits) {
console.log(x);
}
Create a loop that runs as long as i is less than 10 and log the index to the console.
var i = 0;
while (i < 10 ) {
cosole.log(i);
i++
}
Create a loop that runs as long as i is less than 10, but increase i with 2 each time logs the index to the console on each loop.
var i = 0;
while (i < 10) {
console.log(i);
i = i + 2;
}
create a loop that logs index i to console from 0 to 10. But stops if i equals to 5.
for (i = 0, 1 < 10; i++) { console.log(i); if (i == 5) { break; } }
create a loop that logs index i to console from 0 to 10. But skips the log if i equals to 5.
for (i = 0; i < 10; i++) { if (i == 5) { continue; } console.log(i); }