Bird
0
0

Why does a do-while loop always execute its body at least once in PHP?

hard📝 Conceptual Q10 of 15
PHP - Loops
Why does a do-while loop always execute its body at least once in PHP?
ABecause PHP forces one iteration regardless of code
BBecause the condition is evaluated after the loop body executes
CBecause the loop variable is initialized before the loop
DBecause the loop body is inside a function called once
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop execution order

    In a do-while loop, the code block runs first, then the condition is checked.
  2. Step 2: Explain why body runs once

    Since condition is checked after execution, the body always runs at least once.
  3. Final Answer:

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

    Post-condition check ensures one execution [OK]
Quick Trick: Condition checked after body ensures one run [OK]
Common Mistakes:
  • Thinking initialization causes first run
  • Assuming PHP forces iteration arbitrarily
  • Confusing with function call behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes