Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A Python developer is building a quiz application. The program stores correct answers in a list named `key` and user responses in a list named `answers`. The developer wants to count how many positions match between the two lists, stopping the comparison as soon as the first mismatch is found so that a diagnostic message can be shown. Which control-flow statement should be used inside the loop to stop iterating immediately when a mismatch occurs?

⚠ Common exam trap

Test-takers frequently confuse `continue` with `break`; `continue` skips only the current iteration and lets the loop proceed, so it cannot stop the comparison at the first mismatch as required.

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

✓

break

The `break` statement exits the nearest enclosing loop immediately, which is precisely what is needed to stop comparing list positions once the first mismatch appears. `continue` only skips one iteration, `pass` does nothing, and `return` leaves the whole function, so none of those produce the desired early loop termination while preserving subsequent code execution.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    return

    Why it's wrong here

    `return` exits the entire function, not just the loop. If the comparison logic lives inside a function and the developer needs to continue other work after the loop, `return` would end the function prematurely. It is also a syntax error outside a function, so it is not a general loop-control substitute for stopping iteration.

  • ✗

    continue

    Why it's wrong here

    `continue` skips the remainder of the current iteration and moves to the next one, so it would not stop the comparison at the first mismatch. It is useful for skipping a single position, but the requirement is to halt the entire loop when a mismatch is detected, which `continue` cannot accomplish because the loop keeps running.

  • ✗

    pass

    Why it's wrong here

    `pass` is a null statement that does nothing at all; it is a syntactic placeholder, not a loop control mechanism. Placing `pass` after detecting a mismatch would leave the loop running through every remaining position, which contradicts the goal of stopping at the first mismatch to display a diagnostic message early.

  • ✓

    break

    Why this is correct

    `break` immediately terminates the innermost enclosing loop and transfers control to the first statement after the loop. When a mismatch is found, executing `break` stops further comparisons, allowing the program to exit the loop and present the diagnostic message without processing the remaining positions, which is exactly the stated behavior.

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 →

How Courseiva writes practice questions · Editorial policy

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.