How to Stop Loop Before It Has Looped Through All Items in Python


In this example we will show how to stop the loop before it has looped through all the items in Python.

Source Code

str = 'abcdc'
for x in str:
    print(x)
    if x == 'c':
        break

Output:

a
b
c

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments