In this lesson, you’ll see how execution of a
for loop can be interrupted using the
break terminates the loop completely and
continue only terminates the current iteration.
>>> 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
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
nkemakolam on June 13, 2019