Loops and Iteration Flashcards
Why are there various loop mechanisms?
Various loops offer you different ways to determine the start and end points of the loop.
What are the 8 statements for loops provided in Javascript?
- for
- do…while
- while
- labeled
- break
- continue
- for…in
- for…of
What is the ‘for’ loop?
A loop that repeats until a specified condition evaluates to false.
Write down the ‘for’ loop syntax.
for(initialExpression; condition; incrementExpression){ // block of code; }
What is the ‘do…while’ loop?
A loop that repeats until a specified condition evaluates to false.
Write down the ‘do…while’ loop.
do { //block of code; } while (condition);
In the ‘do…while’ loop, the statement (block of code) is executed ___ before the condition is checked. Execution stops when the statement is _____.
once. false.
What is the ‘while’ loop?
A loop that executes its statement as long as the specified condition evaluates to true.
Write down the syntax for the ‘while’ loop?
while (condition is true) {
run//block of code;
}
What is the ‘label’ loop?
A loop that provides a statement with an identifier that lets you refer to it elsewhere in your program. It’s basically creating a nameSpace for a loop statement.
Write down the syntax for the ‘label’ loop.
label:
statement {
}
eg.) markLoop:
while (theMark == true) {
doSomething();
}
What is the ‘break’ statement?
Terminates a loop, ‘switch’, or in a ‘labelled’ statement.
Write down the syntax for the ‘break’ statement.
break;
or with conjunction with the ‘label’ statement:
break([label]);
What is the ‘continue’ statement?
Used to restart a while, do…while, for, or label statements.
The continue statement will jump back to the condition of a ____ loop. In a ___ loop, it jumps to the increment-expression.
while. for.