Technical skill practice

Make an If Statement Do Nothing in Python: pass vs continue

Use pass when a Python if branch needs a syntactic statement but should take no action. pass does not skip the rest of a loop iteration. continue skips to the next iteration, and break leaves the loop. Choose according to the control flow you actually want.

Start with a small, explicit task

Run three tiny traces over the same synthetic numbers. At number two, use pass, continue or break, then observe which numbers reach the following append. Keeping the fixtures identical makes the control-flow difference visible without introducing a different data transformation.

Run the complete example

This original example was checked with Python 3.12.14. Save it as python_pass.py and run it with Python 3.12. It uses only the standard library. The assertions check the stated results.

Expected output

[1, 2, 3]

[1, 3]

[1]

def trace(mode):
    reached = []
    for number in [1, 2, 3]:
        if number == 2:
            if mode == "pass":
                pass
            elif mode == "continue":
                continue
            elif mode == "break":
                break
        reached.append(number)
    return reached
passed = trace("pass")
continued = trace("continue")
broken = trace("break")
assert passed == [1, 2, 3]
assert continued == [1, 3]
assert broken == [1]
print(passed)
print(continued)
print(broken)

Explain the result

In pass mode, execution reaches the append for number two because pass itself has no effect. In continue mode, that append is skipped but number three is still visited. In break mode, number two is not appended and the loop ends before reaching three. The difference concerns the statements after the branch, not merely whether the branch body is empty.

A stub function can also use pass, but calling it then reaches the end without an explicit return and yields None. That may be suitable during drafting; it is not evidence that the intended function is implemented. If a missing operation should fail loudly, decide on an explicit failure rather than leaving a silent placeholder in the completed path.

Avoid these mistakes

Do not use pass to hide an exception that should be investigated or reported. If the desired rule is simply “act when the condition is false,” reversing the condition can be clearer than adding an empty true branch. Preserve pass only when the deliberately empty branch communicates something useful.

Questions, answered

Does pass stop later statements from running?

No. The trace still appends number two after executing pass.

Can an if block be completely empty?

It needs a statement. pass provides one when the branch is intentionally empty.

Sources and examples

ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.

Your experience. A complete resume.

Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.

Free account required. Free-plan PDF exports include a watermark.