← All PCEP Flashcard Decks

Controlling loop execution Flashcards

7 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Controlling loop execution flashcards as text
  1. What happens when a `break` statement is encountered inside a nested `for` loop?

    Answer: It exits only the innermost loop

    `break` only terminates the innermost loop in which it appears, not any enclosing loops.

  2. What is the output of this code? ```python for i in range(5): if i == 3: continue print(i, end=' ') ```

    Answer: 0 1 2 4

    `continue` skips the iteration where `i == 3`, so 3 is not printed.

  3. Which of the following correctly uses `break` inside a `while` loop?

    Answer: while True: break

    `break` is a statement used alone without parentheses or additional keywords.

  4. What does the `else` clause of a `for` loop execute?

    Answer: Only when the loop completes without hitting a `break`

    The `else` clause runs after the loop finishes normally, but is skipped if a `break` exits the loop.

  5. What is the output of: ```python for i in range(3): pass print(i) ```

    Answer: 2

    The loop variable `i` retains its last value after the loop ends, which is 2 for `range(3)`.

  6. How does `continue` differ from `break` inside a loop?

    Answer: `continue` skips to the next iteration; `break` exits the loop

    `continue` moves to the next iteration while `break` terminates the entire loop.

  7. What is the result of this code? ```python x = 10 while x > 0: x -= 3 if x == 4: break print(x) ```

    Answer: 4

    x goes 10→7→4, at which point the `break` fires and the loop exits with x == 4.