Loops and Iteration Flashcards

1
Q

Why are there various loop mechanisms?

A

Various loops offer you different ways to determine the start and end points of the loop.

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

What are the 8 statements for loops provided in Javascript?

A
  1. for
  2. do…while
  3. while
  4. labeled
  5. break
  6. continue
  7. for…in
  8. for…of
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the ‘for’ loop?

A

A loop that repeats until a specified condition evaluates to false.

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

Write down the ‘for’ loop syntax.

A
for(initialExpression; condition; incrementExpression){
// block of code;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the ‘do…while’ loop?

A

A loop that repeats until a specified condition evaluates to false.

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

Write down the ‘do…while’ loop.

A
do {
   //block of code;
} while (condition);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In the ‘do…while’ loop, the statement (block of code) is executed ___ before the condition is checked. Execution stops when the statement is _____.

A

once. false.

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

What is the ‘while’ loop?

A

A loop that executes its statement as long as the specified condition evaluates to true.

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

Write down the syntax for the ‘while’ loop?

A

while (condition is true) {
run//block of code;
}

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

What is the ‘label’ loop?

A

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.

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

Write down the syntax for the ‘label’ loop.

A

label:
statement {
}

eg.) markLoop:
while (theMark == true) {
doSomething();
}

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

What is the ‘break’ statement?

A

Terminates a loop, ‘switch’, or in a ‘labelled’ statement.

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

Write down the syntax for the ‘break’ statement.

A

break;

or with conjunction with the ‘label’ statement:
break([label]);

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

What is the ‘continue’ statement?

A

Used to restart a while, do…while, for, or label statements.

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

The continue statement will jump back to the condition of a ____ loop. In a ___ loop, it jumps to the increment-expression.

A

while. for.

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

What is the ‘for…in’ loop?

A

Iterates a specified variable over all the enumerable properties of an object. For each distinct property, JavaScript executes the specified statements.

17
Q

Write down the syntax for the ‘for…in’ loop?

A
for (variable in object) {
     //block of code
}
18
Q

What is the ‘for…of’ statement?

A

Creates a loop iterating over iterable objects (including array, map, set, arguments objects) invoking a custom iteration hook with statements to be executed for the value of each distinct property.

19
Q

Write the syntax for the ‘for…of’ loop.

A
for (variable of object) {
      // block of code
}
20
Q

What is the difference between a ‘for…in’ loop and a ‘for…of’ loop?

A

A ‘for…in’ loop iterates over property names(keys).

A ‘for…of’ loop iterates over property values.