
# ============================================================
# LOOPS DEMO — Teaching Python loops
# ============================================================

names = ["Alice", "Bob", "Carol", "David", "Eve"]

# ------------------------------------------------------------
# 1. FOR LOOP — iterate over a list
# ------------------------------------------------------------
print("=" * 40)
print("FOR LOOP — printing a list of names")
print("=" * 40)

for name in names:
    print("Hello,", name)

# ------------------------------------------------------------
# 2. INFINITE WHILE LOOP with break
#    Keeps asking for names until the user types "stop"
# ------------------------------------------------------------
print("\n" + "=" * 40)
print("INFINITE WHILE LOOP with break")
print("Type a name and press Enter. Type STOP to quit.")
print("=" * 40)

names = []  # start with an empty list to collect names

while True:                                          # runs forever...
    user_input = input("Enter a name (or STOP): ")
    if user_input.strip().lower() == "stop":         # ...until we break out
        print("You chose to stop entering names.")
        break
    names.append(user_input)
    print(f"  Added '{user_input}' to the list.")

print("Names so far:", names)


# ------------------------------------------------------------
# 3. WHILE LOOP with a condition
#    Continues as long as the user has NOT typed "stop"
# ------------------------------------------------------------
print("\n" + "=" * 60)
print("WHILE LOOP — condition-based (loop while user_input != STOP)")
print("=" * 60)

names = []  # start with an empty list to collect names
user_input = input("Enter a name (or STOP to skip this section): ")

while user_input.strip().lower() != "stop":
    names.append(user_input)
    print(f"  Added '{user_input}' to the list.")
    user_input = input("Enter another name (or STOP to stop): ")

print("Names so far:", names)


# ------------------------------------------------------------
# 4. WHILE LOOP with a counter
#    Prints only the first 3 names from the list
# ------------------------------------------------------------
print("\n" + "=" * 50)
print("WHILE LOOP with a counter — printing only 3 names")
print("=" * 50)

counter = 0

while counter < 3 and counter < len(names):
    print(f"  Name #{counter + 1}: {names[counter]}")
    counter += 1          # increment the counter each pass

print(f"Done! Printed {counter} names.")

# ------------------------------------------------------------
# 4. FOR LOOP variant without a counter
#    Prints only the first 3 names from the list
# ------------------------------------------------------------
print("\n" + "=" * 50)
print("FOR LOOP without a counter — printing only 3 names")
print("=" * 50)

for name in names[:3]:
    print(name)