Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — break & continue Statements

Lesson 23 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

break and continue Statements

break

The break statement immediately terminates the nearest enclosing loop, skipping any remaining iterations.

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

Output:

1
2
3
4

continue

The continue statement skips the rest of the current iteration and moves to the next one — the loop itself keeps running.

for i in range(1, 10):
    if i % 2 == 0:
        continue
    print(i)

Output (only odd numbers):

1
3
5
7
9

break vs continue — visual difference

pass statement (bonus — the "do nothing" placeholder)

for i in range(5):
    if i == 3:
        pass   # placeholder — does nothing, loop continues normally
    print(i)

Example: Find the first number divisible by 7 and 5

for num in range(1, 100):
    if num % 7 == 0 and num % 5 == 0:
        print("Found:", num)
        break

Example: Print numbers 1–10 except multiples of 3

n = 0
while n < 10:
    n += 1
    if n % 3 == 0:
        continue
    print(n)

break/continue inside nested loops

break/continue only affect the innermost loop they are written in:

for i in range(3):
    for j in range(3):
        if j == 1:
            break     # breaks only the inner loop
        print(i, j)