Bird
0
0

Why does a repeat-while loop always execute its body at least once, even if the condition is false initially?

hard📝 Conceptual Q10 of 15
Swift - Loops
Why does a repeat-while loop always execute its body at least once, even if the condition is false initially?
ABecause Swift forces one execution for all loops.
BBecause the loop body is executed before the program starts.
CBecause the condition is checked after the loop body executes.
DBecause the condition is ignored in repeat-while loops.
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop execution order

    In a repeat-while loop, the code inside the loop runs first before any condition check.
  2. Step 2: Explain why condition check is after

    This design ensures the loop body runs at least once, regardless of the condition's initial value.
  3. Final Answer:

    Because the condition is checked after the loop body executes. -> Option C
  4. Quick Check:

    Execution order causes at least one run [OK]
Quick Trick: Condition checked after body, so body runs once always [OK]
Common Mistakes:
  • Thinking Swift forces one execution for all loops
  • Believing condition is ignored
  • Confusing with program start behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes