PCEP Control Flow, Loops, Lists and Logic Practice Question
A developer is writing a Python script to validate a list of usernames. The script must examine each username in the list and print 'Invalid' as soon as a username shorter than 3 characters is found, then stop checking the remaining usernames. Which control flow statement should be used inside the loop to terminate it immediately when the invalid username is encountered?
⚠ Common exam trap
Many exam-takers confuse continue with break, leading to skipping only the current item instead of stopping the entire loop.
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 innermost loop immediately, which is exactly what is needed to stop checking usernames once an invalid one is found. The other statements either skip only one iteration, do nothing, or exit the whole function, so they do not satisfy the requirement to terminate the loop early while continuing the rest of the script.
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
The return statement exits the entire function, not just the loop. If the validation code is inside a function, return would terminate the function and could skip other necessary logic; if not in a function, it causes a syntax error. It is not the correct way to stop only the loop while continuing the rest of the script.
- ✗
pass
Why it's wrong here
The pass statement is a null operation that does nothing when executed. Using pass inside the loop would not stop iteration or alter control flow; the loop would continue checking every username. It is used as a placeholder where code is syntactically required, not for terminating loops, so it cannot fulfill the early-exit requirement.
- ✓
break
Why this is correct
The break statement immediately terminates the innermost loop, so once a short username is found, the loop exits and no further usernames are checked. This matches the requirement to stop checking as soon as an invalid entry is detected, making it the correct control flow statement for early termination inside the loop.
- ✗
continue
Why it's wrong here
The continue statement skips the rest of the current iteration and moves to the next username, so the loop would keep checking remaining usernames instead of stopping. It does not terminate the loop, so it fails the requirement to halt validation immediately upon finding a short username. It only skips processing for that one iteration.
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.