Practice question · Match the pairs
Match each loop keyword or form to what it does.
- while
- for
- break
- continue
- Exits the loop immediately
- Repeats a known number of times or over a collection
- Repeats as long as a condition stays true
- Skips to the next iteration
Hints
- Two of these are loop forms; two are statements that alter a loop from inside.
- One statement leaves the loop entirely; the other only ends the current pass.
Show the answer
- while → Repeats as long as a condition stays true
- for → Repeats a known number of times or over a collection
- break → Exits the loop immediately
- continue → Skips to the next iteration
Why
A while loop is condition-driven and a for loop is count- or collection-driven; break abandons the whole loop while continue merely ends the current pass and moves on. Confusing break with continue changes how much of the loop is skipped.
Practise Loops and Repeated Computation
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Loops and Repeated Computation
- Order the parts of a correct while loop so that it counts up and then stops.
- Modifying a list while looping over it can silently skip elements. Why does removing an item mid-iteration…
- The counter starts at i = 0. Select every loop below that runs its body exactly 5 times.
- An off-by-one error in a loop boundary usually causes a crash, which is what makes it easy to find.