What Are Break, Continue, and Pass Statements in Python?

A quick and direct explanation of these three keywords that will answer the questions what do they do and when to use them

What are Break, Continue, and Pass Statements in Python?

When you’re learning Python, the keywords break, continue, and pass are sure to be scattered throughout the code you look up. Here’s a quick and direct explanation of these three keywords that will answer the questions “what do they do?” and “when should I use them?”


Break: Get Me Out of Here!

The break statement is not new or unique to Python. This command will exit the iteration structure (loop) effectively stopping any further execution from that code block. Use break statements when the loop should not be executed anymore. One of my favorite techniques is breaking out of an infinite loop meant for user input.


Continue: Move Along. Nothing to See Here…

Unlike the break statement which kills the current loop, continue ends the current iteration. What’s the difference? The loop will keep executing with a continue statement. Use this keyword to identify exceptions while looping through a set of data. The below example prevents the printing of matching x,y coordinates.


Pass: Coming Soon!

Depending on the type of code you’re learning from (step-by-step tutorials vs. finished syntax) your exposure to pass statements may be limited. That’s because it is mostly used as a placeholder. Called a null statement, the pass statement is used to fill out a code block without actually doing anything. Let’s say you’re planning out your program and want to lay out the functions and pseudo-coded control structures. The challenge is that Python uses indentations to represent code blocks so the interpreter expects something after certain statements. Use pass to appease the interpreter and allow yourself the freedom to plan and build slowly.

I hope this quick tutorial is helpful for you budding programmers!

Subscribe to Dreams of Fortunes and Cookies

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe