Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

Which TWO of the following statements about Python's for loop are correct? (Choose Two)

⚠ Common exam trap

The PCEP exam often tests the misconception that a `for` loop always executes at least once, but in reality it can iterate zero times over an empty sequence, and they also test the less-known fact that `for` loops support an `else` clause.

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

✓

It can iterate over any sequence

Option B is correct because Python's for loop is designed to iterate over any iterable object, including sequences such as lists, tuples, strings, and ranges, as well as non-sequence iterables like dictionaries, sets, and generators. Option D is correct because Python's for loop supports an optional else clause that executes after the loop completes normally, i.e., without encountering a break statement. Option A is incorrect because a for loop does not take a while-style boolean condition; it iterates over an iterable, whereas while loops use a condition. Option C is incorrect because a for loop over an empty iterable executes zero times, unlike a do-while construct. Option E is incorrect because Python also provides the while loop, so the for loop is not the only loop.

Answer analysis

Option-by-option breakdown

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

  • ✗

    It can be used with a while loop condition

    Why it's wrong here

    A for loop iterates over an iterable and takes no boolean condition; combining it with a while condition is a syntax error. The temptation arises because while loops test a condition each pass, which suits sentinel-driven repetition, and that is exactly the scenario where while, not for, is the correct construct.

  • ✓

    It can iterate over any sequence

    Why this is correct

    A Python for loop works with any iterable object, not just lists or strings, because it relies on the iterator protocol. It calls iter() to obtain an iterator and repeatedly invokes next() until StopIteration. This satisfies the stem's requirement that iteration works across sequences generally.

  • ✗

    It always executes at least once

    Why it's wrong here

    A for loop iterates over a sequence, so an empty sequence causes zero executions; only a while loop with a condition true at entry guarantees at least one pass. It is tempting because loop bodies often run, but that reflects typical inputs, not guaranteed behaviour.

  • ✓

    It can be used with an else clause

    Why this is correct

    Python's for loop supports an optional else clause, which executes after the loop completes normally, without encountering a break statement. This satisfies the stem's requirement about valid for-loop syntax. The else block is skipped only when break terminates iteration early.

  • ✗

    It is the only loop in Python

    Why it's wrong here

    Python also provides the while loop, so the for loop cannot be the only iteration construct. It is tempting because for loops dominate iteration over sequences, ranges and generators, and in idiomatic Python they replace most manual index handling, but while remains necessary for condition-driven repetition.

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 →

How Courseiva writes practice questions · Editorial policy

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.