Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON TEXT / CHAPTER 03 / Learn / LESSON 07
Seventh class. Inside a loop you sometimes want to stop early or skip one step.
break ends the whole loop immediately. continue skips the rest of the current iteration and moves to the next one.
Mini example:
for n in [1, 2, 3, 4]: if n == 4: break if n == 2: continue print(n)
Here 2 is skipped, and at 4 the loop stops — output is 1 and 3.
Common mistake: swapping break and continue; or printing before the check and wondering why the “wrong” value still appears.
Learn: continue skips; break stops the loop.
PROFILE IDLE
›