# A new kind of loop
# while — repeats as long as a condition is True

# ─────────────────────────────────────────────
# Basic while loop
# ─────────────────────────────────────────────

count = 0

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

# 0
# 1
# 2
# 3
# 4

# condition checked before every iteration
# when count reaches 5 — condition is False — loop stops

# ─────────────────────────────────────────────
# The update is your responsibility
# ─────────────────────────────────────────────

# Wrong — infinite loop
# count = 0
# while count < 5:
#     print(count)
#     — count never changes — condition never becomes False

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

# ─────────────────────────────────────────────
# for vs while
# ─────────────────────────────────────────────

# for — you know how many times
for i in range(5):
    print(i)

# while — you know the condition, not the count
count = 0
while count < 5:
    print(count)
    count += 1

# same result — different tool

# ─────────────────────────────────────────────
# Real example — password check
# ─────────────────────────────────────────────

password = "RedHorn"
attempt = ""

while attempt != password:
    attempt = input("Enter password: ")

print("Access granted.")

# you don't know how many attempts the user will need
# the loop doesn't either — it just keeps asking

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

# while condition:     — colon is mandatory
#     block            — 4 spaces indentation
#
# condition checked before every iteration
# you must update something inside — or it runs forever
# if condition is False from the start — loop never runs
