The meaning of Iterate?
To Repeat
What is a Loop?
Repeats a task until specific condition is met (Stopping Condition).
What does a for loop include?
A for loop includes an iterator variable, which can be named anything but it’s best to provide a descriptive name.
Name all three expressions for a for loop?
How is a for loop written?
for (let count = 0; count < 4; count++) {
console.log(count);
}
What is Looping in reverse and how is it written?
A loop in reverse is basically counting backwards but the same concept as a normal loop.
Iterator starts with the highest value.
for (let count = 5; count > 1; count–) {
console.log(count);
}
How is an array index called in a FOR loop?
The FOR lopp iterator can used as a short hand for the index.
What is a nested loop and provide a use case example?
A loop running inside another loop.
Example, to compare two arrays, the outer loop will run for one element (Current). While the inside loop runs for every element in an array and compares to the current outer loop element.
What is a While loop and when would it be used?
A while loop is another form of a loop which is best to be used when the number of loops is undetermined.
How does a While loop differ from a for loop.
The iterator variable is on the outside (Global Scope).
The stopping\test condition in parenthesis after the While keyword.
The iterator statement (Incrementor) inside the code block.
How is while loop written?
let i = 0;
while (i < 5) {
console.log(‘Here’);
i ++;
}
Describe a Do…While loop
The code block will run at least once and then checked against the stopping condition.
If the stopping condition is false then it won’t loop but if true it will loop again.
How is a Do….While loop written?
let i = 1;
let i1 = 1;
Do {
i = i + 2;
i1++;
} while (i1 < 5);
What does the break statement do in a loop?
Creates another stopping\testing condition other than the original, and therefore exiting the loop.
for (i = 0; i < 5; i++) {
console.log(‘here’);
if ( i > 2) {
break;
}
}