Iteration Flashcards

1
Q

for (let let I = 0; I < array.length; I++ )

The above code snippet is a ?

A

for loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
let rep = 1;
while (rep <= 10) {
          //do something

}

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly