# COMMON WHILE MISTAKES
# Each block shows the wrong way, the error it produces, and the right way
# Read through — don't just run it top to bottom

# ─────────────────────────────────────────────
# MISTAKE 1 — Infinite loop — forgetting to update
# ─────────────────────────────────────────────

# Wrong — count never changes — loop runs forever
# count = 0
# while count < 5:
#     print(count)

# Right — update inside the loop
count = 0
while count < 5:
    print(count)
    count += 1

# ─────────────────────────────────────────────
# MISTAKE 2 — Condition is False from the start
# ─────────────────────────────────────────────

# Wrong — loop never runs
count = 10
while count < 5:
    print(count)    # never executes
    count += 1

# no error — just silence
# check your starting value before the loop

# ─────────────────────────────────────────────
# MISTAKE 3 — while True without break
# ─────────────────────────────────────────────

# Wrong — pass does nothing, loop runs forever
# while True:
#     answer = input("Type 'quit': ")
#     if answer == "quit":
#         pass

# Right
while True:
    answer = input("Type 'quit': ")
    if answer == "quit":
        break

# ─────────────────────────────────────────────
# MISTAKE 4 — Converting input inside the condition
# ─────────────────────────────────────────────

# Wrong — crashes if user types a word
# while int(input("Enter a number: ")) != 0:
#     print("Keep going.")

# Right — validate before converting
while True:
    entry = input("Enter a number: ")
    if entry.isdigit():
        if int(entry) == 0:
            break
        print("Keep going.")

# ─────────────────────────────────────────────
# MISTAKE 5 — Off by one in the condition
# ─────────────────────────────────────────────

# Wrong — expecting 1 to 5, getting 1 to 4
count = 1
while count < 5:
    print(count)
    count += 1

# Right
count = 1
while count <= 5:
    print(count)
    count += 1

# < vs <= — one character, completely different result

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

# always update something inside — or loop runs forever
# check condition before loop — it might never run
# every while True needs a reachable break
# validate input before int() — crashes on words
# < vs <= — know which boundary you want included
