javascript-loops Flashcards

1
Q

What is the purpose of a loop?

A

The purpose of a loop is to repeat a segment of code until a condition is met.

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

What is the purpose of a condition expression in a loop?

A

The purpose of a condition expression in a loop is to signal when a loop should terminate.

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

What does “iteration” mean in the context of loops?

A

Iteration means increase the value of the initialized variable or index variable by one or another value check the conditional statement to see if the code block can be run again and if it can, rerun the code block. If not, exit the loop.

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

When does the condition expression of a while loop get evaluated?

A

The condition expression of a while loop gets evaluated before the code block runs. If you want the code to run first, then use a do-while loop.

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

When does the initialization expression of a for loop get evaluated?

A

The initialization expression of a for loop gets evaluated first. This only occurs once at the very start.

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

When does the condition expression of a for loop get evaluated?

A

The condition expression of a for loop gets evaluated right before the code block and right after the final expression. It also happens after initialization to see if the code block can be entered.

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

When does the final expression of a for loop get evaluated?

A

The final expression gets evaluated after the code block and right before the condition.

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

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

The “break;” keyword will exit a loop when called.

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

What does the ++ increment operator do?

A

The ++ increment operator takes the variable and assigns it a value of the value it had assigned to it plus 1.

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

How do you iterate through the keys of an object?

A

To iterate through the keys of an object you can use a for-in loop which looks like: for(var key in object) {}

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