break statement in for loops

PHOTO EMBED

Tue Jun 18 2024 04:11:28 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds #python

#the break statement, causes the loop to immediately terminate.

seq = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in seq:
    #define the condition
    if i == 5:
        break
    print(i)

print('after the loop')
content_copyCOPY

https://www.pynerds.com/break-and-continue-statements-in-python/