0 XP
Chapter 2
Loops
Make things repeat — essential for game loops!
Core Concept
Loops run a block of code multiple times so you don't have to write the same thing over and over.
Theory
Two types of loops:
for loop — repeat a known number of times:
for i in range(5):
print(i) # prints 0, 1, 2, 3, 4
while loop — repeat until a condition is false:
lives = 3
while lives > 0:
print(f"{lives} lives left")
lives -= 1
print("Game Over!")
Live Demo — Run & Explore
Try it live
Loading...
Output will appear here…
Exercise 1 / 1
📝 Write a loop that prints the numbers 1 to 10.
Your solution
Loading...
Output will appear here…
Ask AI Tutor
AI Tutorgemini-3.1-flash-lite-preview
AI
Hi! I'm your AI tutor for Loops. 🎓
Ask me anything about this lesson — what a variable is, why loops are useful, or "why is my code not working?". I'm here to help you understand, not just give you answers!
What's on your mind? 😊