4. Loops Flashcards

1
Q

A ____ is a program construct that repeatedly executes statements while its expression is true and proceeds to subsequent statements once its expression is false.

A

loop

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

A loop’s statements are known as the loop ____.

A

body

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

Each time through a loop’s statements is called a(n) ____.

A

iteration

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

A ____ value is a special value indicating the end of a list, such as a list of positive integers ending with 0, as in 10 1 6 3 0

A

sentinel

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

What are the three components of a for loop?

A
  1. Loop variable initialization (e.g., i = 0)
  2. Loop expression (e.g., i < 10)
  3. Loop variable update (e.g., i += 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which loop is best for situations in which the number of iterations is computable before the loop?

A

For loop

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

Which loop is best for situations in which the number of iterations is not easily computable before the loop.

A

While loop

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

A ____ loop is a loop that appears in the body of another loop. The two loops are referred to as the ____ loop and the ____ loop.

A

nested, inner, outer

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

A ____ loop is a loop that first executes the loop body’s statements, then checks the loop condition.

A

do-while

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

When is a do-while loop useful?

A

When the loop should iterate at least once

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