Skip to main content
← CoursesPython FoundationsModule 1 · Fundamentals of syntaxwhile loopfix13 / 170
💬 Discuss🧪 Playground+75 XP
Task
📝 **Task:** Find the bug in a `while` loop. The program should print 1..5 and stop, but it loops forever. 📋 **Steps:** 1. Look at the body of the `while` loop 2. Counter `count` is never incremented 3. Add `count += 1` inside the loop 4. After 5 iterations `count <= 5` becomes False and the loop ends 💡 **Working example:** ```python n = 1 while n <= 3: print(n) n += 1 # ← without this it would loop forever # 1 # 2 # 3 ``` ⚠️ **Hint:** every `while` must somewhere modify its condition — otherwise infinite loop. 🎯 **Expected output:** ``` 1 2 3 4 5 ```

Keep going

✏️ Write your code here
🐍
Loading Python...
First visit only — ~5-10s. Stays cached afterward.
📊 Result
Press Run to see result...
📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…