Learn Before
Concept

Break Statement

With the break statement we can stop or break out of the loop before it has looped through all the items:

tasks = ["Eat", "Sleep", "Repeat"] for x in tasks: print(x) if x == "Sleep": break

In the example above, the code will print Eat Sleep then the loop will break and Repeat will not be printed.

0

1

Updated 2021-07-21

Tags

Python Programming Language

Data Science