Practice question · Multiple choice
A while loop and a for loop can compute the same result. Why does the choice between them matter?
Hints
- Ask what each loop form announces to the reader.
- 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.
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.