Labs ICT
🎓 SIWES/IT Login

Break & Continue

1 min read | Python Tutorial
🎓

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

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})")