You’ve wandered out into the forest for what feels like two moons. And you keep looping past the same darn tree…

“…Wait. Didn’t I pass this stump already?”
The forest is still, but your footsteps? Not so much. You’ve been looping… And in programming, that’s not always a bad thing.
Making loops work for us
Instead of “do this, and this, and this,” over and over…
We say, “While this is true… keep going.”
Just like our little forest stroll, a while
loop keeps going until we break out of it.
searching_for_exit = True
while searching_for_exit:
print("Still in the forest...")
if not searching_for_exit:
print("Aha! A way out!")
# The indented portion is what happens each lap – It runs again and again.
And when we need a snack…
We can dig through our bento like, “For every item… do this.” to search through our snacks.
bento = ["onigiri", "donut", "juice box"]
for snack in bento:
print("Mmm, a", snack)
# The snack marks the current iteration we're on
Mmm, a Onigiri
Mmm, a Donut
Mmm, a Juice box
So we have two types of loops
Use
while
when you don’t know how many times something needs to repeat. Like wandering until something changes.Use
for
when you're going through a collection of things. Like checking every snack in your bento.
The realization…
The birds? Still flying that same figure-eight. That tree? Same cryptic symbols etched in…
Sometimes we loop on purpose… and sometimes, we know when to skip, or even stop entirely.
Like if we want to skip a snack?
for snack in bento:
if snack == "pickled plum":
print("Bleh")
continue # We skip this snack and don't say Mmm!
print("Mmm, eating:", snack)
When the loop hits “Pickled Plum”, it only says 'bleh', and moves on to the next snack in our bento.
And if we see the same tree too many times
We realize ‘enough is enough.’ That’s when we use break
# The endless forest (while loop)
keep_walking = True
etched_tree_passed = 0
while keep_walking:
if etched_tree_passed < 3:
print("This tree again?!")
etched_tree_passed += 1
else:
print("Forget this! I'm out")
break
The break
statement ends the loop even when the condition is True
. So just like that, You’re free to do something new.
It’s kind of like ripping the engine out of a moving car rather than turning the key. It’s better to stop with intention rather than an abrupt force, but sometimes we just want out.
A new north
The same cryptic, etched tree stands firmly in front of you. Sigh… You gaze up at the sky and notice a brightly lit star.
Loops aren’t just about repetition. They’re about control and now you have it.
“Let’s just see where fate takes me” you mumble as you walk past the tree onto your next adventure.
No more circles. No more loops. Just a path forward.

Quest Log Updated.
while
statements repeat instructions till a condition is metfor
statements repeat a set number of timescontinue
statements skip a step in your loopbreak
statements stop a loop entirely- An iteration variable marks the current lap or item we’re on