Labs ICT
Pro Login

Break & Continue

1 min read | Python Tutorial

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

Python break and continue

break exits the loop immediately. continue skips the rest of the current iteration and moves to the next one.

Using break

Stop the loop when a specific condition is met.

for num in range(1, 10):
    if num == 5:
        break
    print(num)

Using continue

Skip the current iteration and move to the next one.

for num in range(1, 8):
    if num % 2 == 0:
        continue
    print(num)

break in Nested Loops

break only exits the innermost loop it is in.

for i in range(1, 4):
    for j in range(1, 4):
        if j == 2:
            break
        print(f"({i},{j})")