PCEP Control Flow, Loops, Lists and Logic Practice Question
A Python programmer is reviewing a script that processes a list of order totals. The script must print each total that is greater than 100 and stop scanning entirely the first time it encounters a total of exactly 0. Which two statements about the loop logic are correct? (Choose two.)
⚠ Common exam trap
The trap here is treating continue as a way to stop a loop, when it merely skips the remainder of the current iteration and keeps going.
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
✓
A break statement placed inside the loop immediately terminates the loop when the total equals 0.
Stopping a scan at a sentinel value is the classic use case for break, which exits the innermost loop immediately. Pairing it with an if that compares the current total to 0 gives the required early termination. The continue statement only skips to the next iteration, and using exceptions for ordinary control flow is discouraged, so those approaches fail to meet the requirement.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Wrapping the loop in a try block and raising an exception at zero is the idiomatic way to stop iteration.
Why it's wrong here
Raising an exception to end a loop is possible but is not idiomatic for a simple sentinel check. It adds overhead and obscures intent, and an unhandled exception would propagate and crash the script rather than cleanly exit the loop. Python provides break specifically for this purpose, so using exceptions here is unnecessarily complex and error-prone for the stated scenario.
- ✓
A break statement placed inside the loop immediately terminates the loop when the total equals 0.
Why this is correct
The break statement exits the innermost enclosing loop at once, skipping any remaining iterations. Placing it inside an if that checks for a total of exactly 0 fulfills the requirement to stop scanning entirely at that point. Any totals after the zero, whether above 100 or not, are never examined, which is precisely the behaviour the script must exhibit.
- ✓
An if statement comparing the total to 0, followed by break, correctly implements the early exit.
Why this is correct
Combining an if that tests whether the current total equals 0 with a break inside that block creates the exact early-exit behaviour required. When the condition is true, break fires and the loop ends; when false, the iteration proceeds normally. This is the standard idiom for stopping a scan upon encountering a sentinel value in a sequence.
- ✗
A continue statement placed inside the loop would stop the entire scan when the total equals 0.
Why it's wrong here
The continue statement does not terminate a loop; it only skips the rest of the current iteration and proceeds to the next item. If used when the total is 0, the loop would still process every later total, so scanning would not stop. The scenario demands that the scan end completely, which requires break, not continue.
- ✗
The condition for printing must be checked before the zero check, or zero totals could be printed.
Why it's wrong here
Order matters only in that the zero check should prevent further processing. A total of 0 is not greater than 100, so the print condition would never output it even if evaluated first. The real requirement is that the zero check stops the loop, and break accomplishes that regardless of whether the print check comes before or after it, provided break is reached.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.