...

/

Break the Loop (When You Must)

Break the Loop (When You Must)

Learn how to exit or skip within loops.

Sometimes, we don’t want to run the entire code—just part of it—until a certain condition is met, like a user typing “quit” or a robot reaching a goal.
This is where Python gives us control tools like if statements to check conditions, and break to stop a loop immediately when needed.

It’s like saying: “Keep going… until this happens—then stop!”

Stopping a loop when a condition is met

In the example, we use a ...