Choosing While or For
The rule is simple:
Use for when you're walking a collection or repeating a known number of times.
Use while when you're waiting for a condition to change and can't know the count ahead of time.
break works in while loops too, and pairs well with a deliberate forever-loop when the exit condition lives in the middle of the body.
Mark this lesson complete
Signed in, your progress follows you to every device.