Editor

Predict the Output

Beginner · Predict the output · from Python break, continue, pass: Controlling Loop Flow

From the lesson: Python break, continue, pass: Controlling Loop Flow

You're searching through a phone book for your friend's number. Once you find it, do you keep flipping through every remaining page? Of course not - you stop. Or imagine you're reading a list of emails. You skip the spam and only read the real ones. These are everyday examples of controlling the flow of a loop.

Read the lesson

Without running the code, predict exactly what it will print. Trace through each iteration and think about when continue and break trigger.

Then run it to check your answer.

for i in range(1, 8):
if i == 3:
continue
if i == 6:
break
print(i)

More break, continue, pass exercises

All Python exercises · 50 practice problems · Control Flow quiz