Iteration Flashcards
1
Q
for (let let I = 0; I < array.length; I++ )
The above code snippet is a ?
A
for loop.
2
Q
const Person = [‘Isa’,’Muhammad’,’Programmer’];
Write a for loop to iterate through the contents of the array above.
A
for (let I = 0 ; I < person.length; I++) { console.log(person[I]); }
3
Q
What will the “continue” & “Break” keyword do in a for loop?
A
Continue will immediately exit/skip the current iteration while Break will completely terminate the whole loop.
4
Q
const Person = [‘Isa’,’Muhammad’,’Programmer’];
Loop through backwards using the given array above.
A
for (let i = person.length -1 ; i > 0; i -- ) { console.log(person[I]); }
5
Q
let rep = 1; while (rep <= 10) { //do something
}
A
5
Q
let rep = 1; while (rep <= 10) { //do something rep ++; }
A
A while loop. The while loop is perfect fro when the total number of iterations is unknown.