Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.

Range, Break, and Continue

Give Feedback

In this lesson, you’ll see how execution of a for loop can be interrupted using the break and continue statements. break terminates the loop completely and continue only terminates the current iteration.

break example:

>>>
>>> for i in ['foo', 'bar', 'baz', 'qux']:
...     if 'b' in i:
...         break
...     print(i)
...
foo

continue usage example:

>>>
>>> for i in ['foo', 'bar', 'baz', 'qux']:
...     if 'b' in i:
...         continue
...     print(i)
...
foo
qux

Comments & Discussion

nkemakolam on June 13, 2019

wow

marktompkins on Dec. 25, 2019

very interesting!

kbutler52 on Dec. 27, 2019

Thank you so much for breaking this topic down for me! Love how you helped me to understand it!!!!!

DanielHao5 on Jan. 22, 2020

It’s a good intro to this important topic. However, it should be expanded to show some good and practical examples - eg. deep-dive on some edge cases and show how-to approach on those questions.

Abdullah Dev on Feb. 28, 2020

Great work !! easy to understand and follow.

emalfiza on March 10, 2020

Your explanation is so amazing. just wow Darren

markthiele on March 17, 2020

Thanks, very nice!

Become a Member to join the conversation.