PCEP Control Flow, Loops, Lists and Logic Practice Question
Exhibit
>>> data = [[1,2], [3,4], [5,6]] >>> result = [] >>> for row in data: ... for item in row: ... if item % 2 == 0: ... break ... else: ... result.append(row) >>> result [[1,2], [5,6]]
Refer to the exhibit. What does the else clause of the inner for loop do?
⚠ Common exam trap
The PCEP exam often tests the for-else behavior by making candidates confuse it with the if-else pattern, leading them to think the else runs after every iteration or when a condition is false, rather than understanding it as a 'no-break' indicator.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Executes if the inner loop completes without break, meaning no even number in the row.
The else clause of a for loop in Python executes only when the loop completes normally, i.e., without encountering a break statement. In this nested loop, the inner for iterates over elements of a row; if no even number is found (no break), the else triggers, indicating the row has no even numbers. This is why option C is correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Executes if the outer loop condition is false.
Why it's wrong here
The else belongs to the inner for loop, so it depends on that loop's completion or break, not the outer loop's condition. It is tempting because the else sits at the same indentation level as the outer loop's body, which visually suggests association with the outer loop.
- ✗
Executes if the inner loop is broken, meaning an even number was found.
Why it's wrong here
Python's for-else runs only when the loop finishes without a break, so a break caused by finding an even number skips the else entirely. It is tempting because break does terminate the inner loop, but that termination suppresses the else rather than triggering it.
- ✓
Executes if the inner loop completes without break, meaning no even number in the row.
Why this is correct
The else clause attached to a for loop runs only when the loop exhausts its iterable without hitting a break, so it executes when no even number appears in the row. A break would skip it entirely.
- ✗
Executes after each iteration of the inner loop.
Why it's wrong here
The else clause runs once, after the inner loop exhausts its iterable without a break, not after every iteration. It is tempting because the loop body itself repeats each pass, so the trailing else appears to share that per-iteration behaviour, but it executes only at loop exit.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.