Practice question · True or false
A while loop can express any for loop, but some while loops cannot be written as a for loop.
Hints
- What does a for loop bundle together?
- Initialise, test, update, all available either way.
Show the answer
False
Why
False. Both directions hold: a for is a while with the initialiser, test and update written in one place, and any while can be written as a for with those slots filled or left empty. The choice is about readability, for when the iteration count is known up front, while when the stopping condition is discovered as you go.
Practise Loops and Iteration
The app has 6 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.