# while True + break — the classic pattern
# infinite loop controlled by break

# ─────────────────────────────────────────────
# Basic while True
# ─────────────────────────────────────────────

while True:
    answer = input("Type 'quit' to exit: ")
    if answer == "quit":
        break

print("Goodbye.")

# loop asks forever
# break fires when user types "quit"
# program continues after the loop

# ─────────────────────────────────────────────
# Regular while vs while True
# ─────────────────────────────────────────────

# Regular while — condition at the top
answer = ""
while answer != "quit":
    answer = input("Type 'quit' to exit: ")

# while True — decision inside the loop
while True:
    answer = input("Type 'quit' to exit: ")
    if answer == "quit":
        break

# same result — while True is cleaner when exit condition is complex

# ─────────────────────────────────────────────
# Input validation — the classic use case
# ─────────────────────────────────────────────

while True:
    age = input("Enter your age: ")
    if age.isdigit():
        age = int(age)
        break
    print("Numbers only. Try again.")

# keep asking until the user gives a valid number
# you can't know in advance how many tries that takes

# ─────────────────────────────────────────────
# Multiple exit points
# ─────────────────────────────────────────────

while True:
    command = input("Enter command: ")
    if command == "quit":
        print("Goodbye.")
        break
    if command == "exit":
        print("Exiting.")
        break
    print(f"Command '{command}' received.")

# one loop — multiple ways out

# ─────────────────────────────────────────────
# Quick reference
# ─────────────────────────────────────────────

# while True:          — runs forever
#     if condition:
#         break        — the only exit
#
# always make sure break can be reached
# every while True needs at least one break inside
# use when exit condition lives inside the loop
