Day 8: Hard Mode
Read carefully before starting the Hard Challenge!
Imagine you're a robot cleaning a room. You keep picking up toys over and over until the room is clean. That's exactly what a loop does in programming — it repeats an action again and again.
while True?In Python, while True creates a loop that runs forever — or at least until
you tell it to stop. The word True means "yes, keep going!" so the loop never stops on its
own.
while True is the game running,
and break is the quit button!
break?The break statement is your emergency exit. When Python reaches a
break inside a loop, it immediately stops the loop and continues with the
rest of the program.
Without break, a while True loop would run forever and crash your program!
That's why they always go together.
Here's the basic structure. Notice the colon : after
while True — Python needs it!
This program keeps asking for a password until the user types the correct one:
What happens here step by step:
True is always true)break to exit
Loops are perfect for menus because the user might want to choose multiple options:
: after while Truebreak somewhere inside the loop so it can stop📚 You've finished reading the theory! Time to prove your skills.