Skip to main content

Command Palette

Search for a command to run...

Difference between break and continue in Python

Published
1 min read
A

👋 Welcome to my Hashnode blog! I'm a tech enthusiast and cloud advocate with expertise in IT, backup solutions, and cloud technologies. Currently, I’m diving deep into Python and exploring its applications in automation and data management. I share insights, tutorials, and tips on all things tech, aiming to help fellow developers and enthusiasts. Join me on this journey of learning and innovation!

(1) With the break statement we can stop the loop even if the while condition is true:

Exit the loop when i is 3:

i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1

o/p :

1

2

3

(2) With the continue statement we can stop the current iteration, and continue with the next:

Continue to the next iteration if i is 3:

i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)

o/p:

1

2

4

5

6

More from this blog

PythonChallenge

11 posts

Welcome to my Python blog, where I share my journey of learning and exploring the versatile world of Python programming! 🌟

Let’s code, learn, and grow together in the world of Python programming!