4. Loops Flashcards
A ____ is a program construct that repeatedly executes statements while its expression is true and proceeds to subsequent statements once its expression is false.
loop
A loop’s statements are known as the loop ____.
body
Each time through a loop’s statements is called a(n) ____.
iteration
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
sentinel
What are the three components of a for loop?
- Loop variable initialization (e.g., i = 0)
- Loop expression (e.g., i < 10)
- Loop variable update (e.g., i += 1)
Which loop is best for situations in which the number of iterations is computable before the loop?
For loop
Which loop is best for situations in which the number of iterations is not easily computable before the loop.
While loop
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.
nested, inner, outer
A ____ loop is a loop that first executes the loop body’s statements, then checks the loop condition.
do-while
When is a do-while loop useful?
When the loop should iterate at least once