javascript-loops Flashcards
What is the purpose of a loop?
The purpose of a loop is to repeat a segment of code until a condition is met.
What is the purpose of a condition expression in a loop?
The purpose of a condition expression in a loop is to signal when a loop should terminate.
What does “iteration” mean in the context of loops?
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.
When does the condition expression of a while loop get evaluated?
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.
When does the initialization expression of a for loop get evaluated?
The initialization expression of a for loop gets evaluated first. This only occurs once at the very start.
When does the condition expression of a for loop get evaluated?
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.
When does the final expression of a for loop get evaluated?
The final expression gets evaluated after the code block and right before the condition.
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
The “break;” keyword will exit a loop when called.
What does the ++ increment operator do?
The ++ increment operator takes the variable and assigns it a value of the value it had assigned to it plus 1.
How do you iterate through the keys of an object?
To iterate through the keys of an object you can use a for-in loop which looks like: for(var key in object) {}