javascript-loops Flashcards
What is the purpose of a loop?
Loops are used in JavaScript to perform repeated tasks based on a condition. Conditions typically return true or false when analysed. A loop will continue running until the defined condition returns false .
What is the purpose of a condition expression in a loop?
The condition is a boolean expression that determines whether the for should execute the next iteration. The for statement evaluates the condition before each iteration. If the condition is true (or is not present), it executes the next iteration.
What does “iteration” mean in the context of loops?
Iteration in coding is a way of repeating things easily. We can use the Data Type of Array, and For Loops to make it easy to repeat things like printing out things to a web page.
How many times the loop runs
When does the condition expression of a while loop get evaluated?
The do…while statement creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
When does the initialization expression of a for loop get evaluated?
An expression (including assignment expressions) or variable declaration evaluated once before the loop begins. Typically used to initialize a counter variable. This expression may optionally declare new variables with var or let keywords. Variables declared with var are not local to the loop, i.e. they are in the same scope the for loop is in. Variables declared with let are local to the statement.
The result of this expression is discarded.
When does the condition expression of a for loop get evaluated?
An expression to be evaluated before each loop iteration. If this expression evaluates to true, statement is executed. This conditional test is optional. If omitted, the condition always evaluates to true. If the expression evaluates to false, execution skips to the first expression following the for construct.
(In other words, the for statement evaluates the condition before each iteration. If the condition is true [or is not present], it executes the next iteration. Otherwise, it’ll end the loop.)
When does the final expression of a for loop get evaluated?
An expression to be evaluated at the end of each loop iteration. This occurs before the next evaluation of condition. Generally used to update or increment the counter variable.
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
A break statement will exit the loop before the condition expression evaluates to false.
What does the ++ increment operator do?
The increment operator ( ++ ) increments (adds one to) its operand and returns a value.
How do you iterate through the keys of an object?
For in loop