Bird
0
0

What happens first when a PHP for loop starts executing?

easy📝 Conceptual Q1 of 15
PHP - Loops
What happens first when a PHP for loop starts executing?
AThe loop body executes before any condition check
BThe condition is checked after the first iteration
CThe initialization statement runs once before the loop starts
DThe increment statement runs before the first iteration
Step-by-Step Solution
Solution:
  1. Step 1: Understand the for loop structure

    A PHP for loop has three parts: initialization, condition, and increment. The initialization runs once at the start.
  2. Step 2: Execution order at loop start

    The initialization runs first, then the condition is checked before the loop body executes.
  3. Final Answer:

    The initialization statement runs once before the loop starts -> Option C
  4. Quick Check:

    Initialization runs first = D [OK]
Quick Trick: Initialization runs once before condition check [OK]
Common Mistakes:
  • Thinking increment runs before first iteration
  • Assuming loop body runs before condition check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes