while
for i in
range()
break
+= 1
continue
count
loop
Unit 3 of 5

Repetition

Why write the same thing 100 times when Python can do it for you? Loops are the engine of automation — and one of programming's most powerful ideas.

5
Lessons
20
Challenges
1
Project
What You'll Learn

Skills Unlocked in This Unit

🔄

while Loops

Repeat code while a condition stays true — countdowns, games, retries.

📋

for Loops & range()

Iterate a fixed number of times with precise control over start, stop, and step.

📊

Accumulator Patterns

Build running totals, counts, max/min tracking, and string construction.

🔲

Nested Loops

Loops inside loops for grids, tables, and 2D patterns.

âšī¸

break & continue

Fine-grained loop control — exit early or skip iterations.

🎮

Build a Game

Combine everything into a full number-guessing game with replay.

Try It Now

Loop Visualizer

Watch how Python executes a loop step by step. Click a loop type to see it in action.

🔄 Step-by-Step Execution

Interactive
Execution Trace
Lesson Roadmap

Your Path Through Unit 3

Click any lesson to see its challenges.

🔄

3.1 while Loops

4 challenges

Repeat actions while a condition is true. Learn loop variables, avoid infinite loops, and use break for early exit.

whileloop variableinfinite loopsbreaksentinel values
Challenges
Countdown — 10 to 1, Liftoff!
Guess the Number — too high/too low
Sum Until Zero — running total
Collatz Sequence — math mystery
Start Lesson →
📋

3.2 for Loops & range()

4 challenges

Iterate a fixed number of times with for and range(). Master start, stop, and step parameters.

forrange()start, stop, steploop variable
Challenges
Times Table — multiply by N
Sum of N — add 1 to N
Staircase — right-aligned # steps
FizzBuzz — the classic
Start Lesson →
📊

3.3 Loop Patterns & Accumulation

4 challenges

Master the accumulator, counter, and max/min patterns. Build strings and totals inside loops.

accumulatorcountermax/min+=string building
Challenges
Average Calculator — running sum
Digit Counter — // and %
Star Triangle — pattern building
Prime Checker — loop + logic
Start Lesson →
🔲

3.4 Nested Loops

4 challenges

Put loops inside loops to build grids, tables, and 2D patterns. Understand inner vs. outer iteration.

nested forgridstables2D patterns
Challenges
Grid Printer — N×M dots
Multiplication Table — 1–10
Box Drawer — hollow rectangle
Diamond — * diamond shape
Start Lesson →
âšī¸

3.5 break, continue & Loop-Else

4 challenges

Fine-tune loop behavior: exit early with break, skip iterations with continue, and discover for...else.

breakcontinuefor...elsewhile...else
Challenges
First Vowel — find with break
Skip Negatives — continue pattern
Password Attempts — 3 tries
Prime Finder — for...else
Start Lesson →
đŸ—ī¸

Unit Project Number Guessing Game

capstone

Build a full-featured guessing game: random number, hint system, attempt counter, play-again loop, and high-score tracking.

while loopsfor loopsbreakaccumulatornested logicrandom
What You'll Build
Random number generation
Too high / too low hints
Attempt counter & play-again loop
High-score tracking across rounds
Start Project →

Ready to Loop?

Lesson 3.1 introduces while — the loop that keeps going until you tell it to stop.

Begin Lesson 3.1 →
Prerequisite: Unit 2 (Conditionals)