Physics I / Algorithms, variables, and control flow
Practice question · Multiple choice

A while loop and a for loop can compute the same result. Why does the choice between them matter?

Hints
  1. Ask what each loop form announces to the reader.
  2. Consider iterating until a numerical method converges.
Show the answer

A. When the number of iterations is not known in advance

Why

The two express different intentions. Convergence loops have no known trip count, and forcing them into a for hides the real termination condition.

Read the lesson: Algorithms, variables, and control flow →

Practise Algorithms, variables, and control flow

The app has 8 more questions on this lesson, and keeps your place in the course. Physics I is free to start.

More questions on Algorithms, variables, and control flow