5.6. Preview Questions#
Complete these questions before class to prepare for the chapter. Use the dropdowns to check your answers.
5.6.1. True or False#
1. A for loop must always count upward.
Answer
False — The update expression can decrement: i-- is perfectly valid.
2. The break statement exits the nearest enclosing loop.
Answer
True — break jumps to the statement after the closest loop.
3. The body of a while loop may never execute if the condition is false initially.
Answer
True — The condition is checked before the first iteration.
4. A for loop and a while loop can always be used interchangeably.
Answer
True — Every for loop can be rewritten as a while loop and vice versa.
5. continue skips the rest of the loop body and moves to the next iteration.
Answer
True — continue jumps to the loop’s update/condition check.
5.6.2. Multiple Choice#
1. How many times does for (int i = 0; i < 5; i++) execute its body?
a) 4
b) 5
c) 6
d) Infinite
Answer
b) 5 — i takes values 0,1,2,3,4 — five iterations.
2. Which loop type is best when the number of iterations is unknown in advance?
a) for
b) foreach
c) while
d) do-while
Answer
c) while — while tests a condition each iteration without requiring a known count.
3. What does continue do inside a loop body?
a) Exits the loop
b) Restarts the program
c) Skips to the next iteration
d) Pauses execution
Answer
c) Skips to the next iteration — continue skips remaining statements in the current iteration.
4. A do-while loop differs from a while loop in that:
a) It uses different syntax only
b) It always executes the body at least once
c) It cannot use break
d) It only works with integers
Answer
b) It always executes the body at least once — The body runs before the condition is first evaluated.
5. What value does i hold after for (int i = 0; i < 3; i++) {}?
a) 2
b) 3
c) 4
d) 0
Answer
b) 3 — The loop exits when i == 3, so i is 3 after the loop ends.
Footnotes