Computer Science I / Loops and Repeated Computation
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
  1. Two of these are loop forms; two are statements that alter a loop from inside.
  2. 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.

Read the lesson: Loops and Repeated Computation →

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