🌱 Junior Track 05 of 08

5. Loops & Iteration

Master iteration constructs in Python: `for` sequence loops, `while` conditional loops, `range()` sequence generator, `break`, `continue`, `pass`, `nested loops`, `loop else`, and sequence iteration protocols.

👁️ Views: 0
# JUNIOR PYTHON TRACK 05 — LOOPS & ITERATION

# 1. for loop with range()
evens = []
for i in range(10):
    if i % 2 == 0:
        evens.append(i)

# 2. while loop & break
counter = 0
while counter < 100:
    counter += 10
    if counter == 50:
        break

# 3. Loop else clause
target = 42
numbers = [10, 20, 30]
found = False
for num in numbers:
    if num == target:
        found = True
        break
else:
    # Runs ONLY when break is not triggered
    search_msg = "Target not in list"

print(f"Evens: {evens}, Counter: {counter}, Status: {search_msg}")

⭐ Rate Track 05: Loops & Iteration (1 to 5 Stars)

Your rating is stored directly in the database. Average: 5.0 / 5 (1 rating)

★ ★ ★ ★ ★
← 4. Conditionals 🌱 Junior Hub Next Module: 6. Collections →