# The end of the loop might not be the end
# for...else — else runs when the loop completes without break

# ─────────────────────────────────────────────
# Basic for...else
# ─────────────────────────────────────────────

word = "Bull"

for letter in word:
    print(letter)
else:
    print("Loop complete.")

# B
# u
# l
# l
# Loop complete.

# ─────────────────────────────────────────────
# When else does NOT run — break interrupts
# ─────────────────────────────────────────────

word = "Bull"

for letter in word:
    if letter == "u":
        break
    print(letter)
else:
    print("Loop complete.")    # never runs — break interrupted

# B

# ─────────────────────────────────────────────
# Real use case — search pattern
# ─────────────────────────────────────────────

word = input("Enter a word: ")
target = input("Enter a letter to find: ")

for letter in word:
    if letter == target:
        print(f"Found '{target}'.")
        break
else:
    print(f"'{target}' not found.")

# found     → break fires → else skipped
# not found → loop completes → else runs

# ─────────────────────────────────────────────
# Empty sequence — else still runs
# ─────────────────────────────────────────────

word = ""

for letter in word:
    print(letter)
else:
    print("Loop complete.")    # runs — no iterations, no interruption

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

# for item in sequence:
#     # loop body
# else:
#     # runs when loop completes without break
#
# else runs     — loop finished without break
# else skipped  — break interrupted the loop
# else runs     — sequence was empty
