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…

Variables & Values
Functions