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.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

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

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!

paritalagt on April 5, 2020

its good explanation ,but you should include some advanced concept with for loop

jasonwilliams78 on May 1, 2020

Yes this is a great intro, but I could sure use more depth to the for loop using compounding logic on an intermediate level

Ghani on Oct. 15, 2020

Very good tutorial Darren; thank you so much!

Become a Member to join the conversation.