Member-only story

Python Programming

How to Use break, continue and pass in Python Programming

Learn how, when and why to use break, continue and pass in Python

Suraj Gurav
Towards Data Science
6 min readMar 21, 2022

https://pixabay.com/photos/bulletin-board-stickies-post-it-3127287/

Python — being flexible — is the best solution to automate and to do repetitive tasks in efficient way!

In Python (and other programming languages also), the concept of loops helps to iterate over a list, tuple, string, dictionary, and a set.

Loops iterate over a block of code until the test expression is false, but sometimes we wish to terminate the current iteration or even the whole loop without checking test expression.

This can be achieved using few keywords which can be used to alter the flow or execution of the loops. And in Python those keywords are — break, continue, pass. 💡

And it is important to know when and how to use these keywords to control the flow of your loop correctly!

Therefore, in this article, I am discussing (with examples) when-why-how of break, continue and pass in Python.

The concept behind these keywords is same irrespective of the programming language!

Let’s get started!

break statement in Python

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in Towards Data Science

Your home for data science and AI. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

Written by Suraj Gurav

Analytics professional and writer. I write about Data Science, Python, SQL & interviews. Join Medium today to get all my articles: https://tinyurl.com/3fehn8pw

Responses (3)

What are your thoughts?

Very well explained with simple examples. Love it!

unlocking our smartphone by using a password. Technically, the phone unlocking process is a for loop and asks continuously for the password. when a correct password is entered, a break ...

Awesome example, i never thought like this