Study guide
Break, Continue, Pass, Loop Else, and Nesting
PCEP Certified Entry-Level Python Programmer Study Guide Exam
Track your progress as you read
Finished sections get a check mark.
1 PCEP Exam Map and Study Strategy
Current PCEP-30-02 Facts How PCEP Tests Code Reading Official Resources and Ethical Prep Four-Week Study Plan and Readiness
2 Computer Programming and Python Fundamentals
1.1 Lexis, Syntax, Semantics, and Indentation 1.2 Identifiers, Keywords, Comments, and Basic Program Structure 1.3 Literals, Types, and Numeral Systems 1.4 Operators, Precedence, and Type Conversion 1.5 print(), input(), and Console Tracing
3 Control Flow
Boolean Expressions, Comparisons, and Truthiness If, Elif, Else, and Decision Trees While Loops and Sentinel Patterns For, Range, and Iteration Patterns Break, Continue, Pass, Loop Else, and Nesting
4 Data Collections
Indexing, Slicing, and Sequence Rules Lists, Mutation, Methods, and Aliasing Tuples, Immutability, and Packing Dictionaries, Keys, Membership, and Iteration Strings, Sets, and Collection Choice
5 Functions and Exceptions
def, return, None, and Call Flow Parameters, Arguments, Defaults, and Keywords Scope, Shadowing, global, and Local Errors Exception Types, try, except, else, and finally Recursion, Debugging, and Final Code Reading
Break, Continue, Pass, Loop Else, and Nesting
Key Takeaways Explain This Topic AI
break exits only the nearest enclosing loop and prevents that loop's else clause from running.
continue skips the rest of the current iteration and moves to the next loop condition or next iterable value.
pass is a do-nothing placeholder; it satisfies syntax but does not skip later statements in the block.
A loop else clause runs only when the loop finishes normally without executing break.
Nested-loop PCEP questions should be traced with separate columns for outer value, inner value, output, and exit event.
Last updated: June 2026
break
break exits the nearest enclosing loop immediately; statements after the loop may still run, but the current loop body stops. for n in range(5):
if n == 3:
- break
- print(n)
This prints 0 , 1 , 2 . When n becomes 3 , break exits before the print .
In nested loops, break exits only the inner loop that contains it; the outer loop continues. for row in range(2):
for col in range(3):
if col == 1:
- break
- print(row, col)
The outer loop advances to the next row after each inner break. Python has no labeled break, so to leave both loops you need a flag or a function return .
continue
continue skips the rest of the current iteration. In a for loop Python moves to the next iterable value; in a while loop it returns to the condition check. for n in range(5):
if n % 2 == 0:
- continue
- print(n)
This prints 1 and 3 . Even numbers hit continue , so their print is skipped. The dangerous version is a while loop whose counter update sits below continue — that update is skipped and the loop can run forever.
pass
pass does nothing. It is a placeholder where Python's grammar requires a statement but you have no action yet. for n in range(3):
if n == 1:
- pass
- print(n)
This prints 0 , 1 , 2 . pass does not mean skip the rest of the block; it performs no action and execution continues to the next statement. Contrast the three:
- Keyword Effect
- break leave the loop entirely
- continue jump to the next iteration
- pass do nothing, fall through to the next line
- Loop else
Python allows else on both for and while . The loop else runs only if the loop finished without executing break . for ch in 'abc':
if ch == 'x':
- print('found')
- break
else:
print('missing')
This prints missing because the loop never breaks. Had a break fired, the else would be skipped. Read loop else as "no break happened," not as the negation of the loop condition. This is a textbook search pattern: break on a hit, else to report no hit.
Nested-loop trace table
Finish the entire inner loop for one outer value before moving on. Use columns for each piece.
- Outer Inner Event Output
- 0 0 print 00
- 0 1 break inner none
- 1 0 print 10
- 1 1 break inner none
This prevents the most common error: believing a single break exits all loops. It also makes continue easy to follow because you can mark exactly which iteration was skipped.
Exam traps
Check indentation before deciding whether an else belongs to an if or to a loop. Remember that break suppresses only the else attached to the loop it leaves. Remember that continue does not end the loop; it advances to the next iteration. Treat pass as a syntactically valid blank line, not a hidden control command. And recall that break / continue outside any loop raise a SyntaxError .
continue in a while loop is the dangerous case
In a for loop, continue is safe because the loop variable advances automatically from the iterable. In a while loop, continue returns to the condition test and can skip the very statement that updates the counter. i = 0
while i < 5:
if i == 2:
- continue # i is never incremented again
- print(i)
- i += 1
When i reaches 2, continue jumps back to the test with i still 2, looping forever. The fix is to update i before continue . Recognizing this infinite-loop pattern is a frequent PCEP exam item.
break exits one level only
Because Python has no labeled break, leaving nested loops requires a flag or wrapping the loops in a function and using return . found = False
for row in grid:
for cell in row:
if cell == target:
- found = True
- break
if found:
break
The inner break leaves the inner loop; the outer if found: break then leaves the outer loop. The exam wants you to know a single break cannot escape both at once.
Loop else as a search reporter
The for / else idiom is the canonical "search and report" pattern. The else says no break happened, meaning nothing was found. nums = [2, 4, 6]
for n in nums:
if n % 2 == 1:
- print('odd found')
- break
else:
print('all even')
No odd value exists, so the loop completes without breaking and the else prints all even .
Quick-reference behavior table
- Construct In a for loop In a while loop Effect on loop else
- break leaves the loop now leaves the loop now else is skipped
- continue next iterable value back to condition (skips updates below it) else still possible
- pass no effect no effect no effect
- normal end else runs else runs else runs
- Final tracing routine
For nested or control-heavy snippets: complete the inner loop fully for each outer value; mark each break / continue / pass event in its own row; verify which loop a break actually exits; and only after the trace decide whether any loop else runs. This disciplined approach is what lets you finish the Control Flow questions — the largest slice of the exam — accurately within the time limit.