Back to Blog
Python

python pass vs continue: When to Use Each

python pass vs continue: Compare Python's pass and continue: what each does, where they differ in loops, and which fits placeholders, exception handlers, and iteration...

pythoncontrol-flowloopscode-readabilityexception-handlingsyntax
Editorial diagram contrasting Python's pass statement, a no-op placeholder, with continue, which advances a loop to its next iteration.

The difference between python pass vs continue is easy to miss because both statements appear inside similar-looking blocks, yet they do not overlap in behavior. pass is a no-op placeholder that executes without doing anything. continue is a loop-control statement that stops the current iteration and moves to the next one. Using the wrong one changes program behavior in ways that are often silent.

What pass Does in Python

pass is a statement that produces no operation. The Python grammar requires an indented block after certain constructs, such as class definitions, function definitions, and exception handlers. When you need the block to exist but have no code to run yet, pass satisfies the syntax requirement.

class PendingService: pass
def retry_placeholder(): pass
try: result = external_api_call() except TimeoutError: pass

In each case, pass tells the parser that the block is intentionally empty. Without it, the code raises an IndentationError or SyntaxError. The statement has no runtime effect; it exists purely to satisfy the grammar.

What continue Does in Python

continue is a control-flow statement valid only inside a for or while loop. When executed, it immediately ends the current iteration, skips any remaining statements in the loop body, and proceeds to the next iteration.

for record in records: if record.status == "archived": continue process(record)

Archived records never reach process(record). The loop advances to the next record, and the rest of the loop body is bypassed for that iteration.

The Key Difference in a Loop

The difference becomes visible when both statements appear in the same position:

for item in items: if item is None: pass print(item)

With pass, the print(item) still runs for None items because pass does not alter control flow. The loop body continues normally.

for item in items: if item is None: continue print(item)

With continue, the print(item) is skipped for None items because the iteration ends early. This is the core behavioral difference: pass leaves the loop flow untouched, while continue redirects it.

Common Mistakes That Mix Up pass and continue

A frequent mistake is using pass inside a loop when the intent is to skip an iteration. The code still runs the rest of the loop body, which may process data that should have been filtered out. The bug is silent because the code does not raise an error; it simply produces different output.

Another mistake is using continue outside a loop. That raises SyntaxError: 'continue' not properly in loop. The statement must be lexically inside a for or while body; placing it in a helper function called from a loop does not work.

A third confusion involves exception handlers. pass in an except block intentionally swallows an exception, which is a deliberate design choice. continue cannot be used there unless the handler itself is inside a loop, and even then it would skip to the next iteration rather than handle the exception locally.

Choosing Between pass and continue

Aspectpasscontinue
Statement typeNo-op placeholderLoop control
Runtime effectNoneEnds current iteration
Valid outside a loopYesNo
Typical usePlaceholder for future codeFilter items in a loop

Use pass when the block must exist but no action belongs there yet, such as a stub class, an empty function, or an exception handler that deliberately ignores a failure. Use continue when the current iteration should stop early and the loop should advance, such as skipping invalid records or filtering out unwanted values.

Readability and Maintainability Concerns

pass in a loop body is often a sign that the loop is incomplete. A reviewer may read it as "this branch is intentionally empty for now," which is different from "this branch should skip the rest of the iteration." When the intent is filtering, continue communicates that clearly.

continue also reduces nesting. Instead of wrapping the rest of the loop body in an if block, you can check the condition, call continue, and keep the remaining code at a single indentation level. That improves readability when the loop body is long.

for record in records: if record.status == "archived": continue if not record.valid: continue process(record)

The guard clauses make the loop easier to follow than a deeply nested equivalent.

Runtime Behavior and Compatibility

Both statements are core language features. They require no imports and behave identically across Python implementations and versions. pass compiles to a no-op, so it adds no runtime cost. continue changes the loop's control flow but adds no meaningful overhead beyond the branch itself.

Because both are part of the language grammar rather than the standard library, they work the same way in CPython, PyPy, and other Python implementations. The only constraint is syntactic: continue must appear inside a loop body, while pass is valid anywhere a statement is required.

python pass vs continue: Syntax and Use Cases | RYUSLOG DEV