Python / Core Python Fundamentals Interview Questions
What do the pass, break, and continue statements do in Python loops?
These three keywords control loop flow in different ways, and confusing them is a common source of bugs.
pass: Does absolutely nothing. It is a syntactic placeholder used wherever Python requires a statement but you have nothing to write yet — an empty function body, an empty class, a stub except block. It is not a loop-control statement; it just lets the loop body be syntactically valid.
def todo(): pass # implement later for i in range(5): pass # loop runs 5 times doing nothing
break: Immediately exits the innermost enclosing loop. Any else clause on the loop is skipped. Typical use: linear search where you want to stop as soon as you find the item.
for name in ['Alice', 'Bob', 'Carol']: if name == 'Bob': print('Found Bob') break
continue: Skips the rest of the current iteration and jumps immediately to the next one. The loop itself keeps running.
for i in range(10): if i % 2 == 0: continue # skip even numbers print(i) # prints 1 3 5 7 9
A common interview trick question: what does pass do in a loop that also prints something before the pass? The answer is: the print still executes — pass only affects the statement position, not any previous code in the block.
More Related questions...