Back
+10 XP
Concept

The while Loop

A `while` loop runs continuously as long as its condition remains `True`:

python
ammo = 3
while ammo > 0:
    print("Bang!")
    ammo -= 1

# 56. The while Loop A `while` loop runs continuously as long as its condition remains `True`: ```python ammo = 3 while ammo > 0: print("Bang!") ammo -= 1 ``` Forget to decrease `ammo`, and the condition stays permanently `True`, trapping your CPU in an eternal loop of doom.

Checkpoint

What happens if a `while` loop's condition never turns `False`?

Practice

Write a `while` loop starting at `count = 3` that prints `count` and decreases it by 1 each time (`count -= 1`) until it hits 0.

Terminal
01
Tap code blocks below to assemble
Available Blocks