break, continue, and Early Exit
Control loops precisely.
Steer a Loop Precisely
Sometimes you must leave a loop early or skip a single pass. Mojo gives you break and continue for exactly that control. 🎛️
Stop Early with break
The break statement exits the loop immediately. No further passes run, and execution jumps to the code after the loop.
for i in range(10):
if i == 3:
breakAll lessons in this course
- Making Choices with if/else
- Looping with while
- Iterating with for and range
- break, continue, and Early Exit