⚠️ Copying, pasting, and AI assistance are not allowed in this challenge! Write your own answers. ⚠️
🏠 Home

📖 While True Loops & Break

Read carefully before starting the Hard Challenge!

🔄 What is a Loop?

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.

♾️ What is 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.

🎮 Think of it like this: Imagine a video game that keeps running level after level. It doesn't stop by itself — you have to press the quit button. while True is the game running, and break is the quit button!

🛑 What is 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.

📝 How Does the Syntax Look?

Here's the basic structure. Notice the colon : after while True — Python needs it!

while True:
    # Code here runs again and again
    if some_condition:
        break # Exit the loop!

🔐 Real Example: Password Checker

This program keeps asking for a password until the user types the correct one:

while True:
    password = input("Enter your password: ")
    if password == "secret123":
        print("Password accepted!")
        break # Stop asking!
    else:
        print("Incorrect, try again.")

What happens here step by step:

🍽️ Another Example: A Simple Menu

Loops are perfect for menus because the user might want to choose multiple options:

while True:
    print("1. Say Hello")
    print("2. Exit")
    choice = input("Pick an option: ")

    if choice == "1":
        print("Hello! 👋")
    elif choice == "2":
        print("Goodbye!")
        break
    else:
        print("Invalid option, try again.")
⚠️ Remember these 3 golden rules:
1. Always put a colon : after while True
2. Always include a break somewhere inside the loop so it can stop
3. The code inside the loop must be indented (moved to the right with spaces)

📚 You've finished reading the theory! Time to prove your skills.