Loops Flashcards

(15 cards)

1
Q

The meaning of Iterate?

A

To Repeat

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

What is a Loop?

A

Repeats a task until specific condition is met (Stopping Condition).

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

What does a for loop include?

A

A for loop includes an iterator variable, which can be named anything but it’s best to provide a descriptive name.

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

Name all three expressions for a for loop?

A
  1. Initialisation
    Starts the loop or names the iterator variable.
  2. Stopping Condition
    Checked against the iterator variable, runs if true and stops when false.
  3. Iterator Statement
    Update the iterator variable on each run.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is a for loop written?

A

for (let count = 0; count < 4; count++) {
console.log(count);
}

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

What is Looping in reverse and how is it written?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is an array index called in a FOR loop?

A

The FOR lopp iterator can used as a short hand for the index.

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

What is a nested loop and provide a use case example?

A

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.

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

What is a While loop and when would it be used?

A

A while loop is another form of a loop which is best to be used when the number of loops is undetermined.

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

How does a While loop differ from a for loop.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How is while loop written?

A

let i = 0;
while (i < 5) {
console.log(‘Here’);
i ++;
}

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

Describe a Do…While loop

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is a Do….While loop written?

A

let i = 1;
let i1 = 1;

Do {
i = i + 2;
i1++;
} while (i1 < 5);

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

What does the break statement do in a loop?

A

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;
}
}

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