Bird
0
0

Identify the syntax error in this PHP loop:

medium📝 Debug Q7 of 15
PHP - Loops
Identify the syntax error in this PHP loop:
for $i = 0; $i < 3; $i++ {
  echo $i;
}
AUsing curly braces instead of parentheses
BMissing semicolon after echo statement
CIncorrect variable name
DMissing parentheses around the for loop parameters
Step-by-Step Solution
Solution:
  1. Step 1: Check for loop syntax

    PHP requires parentheses around for loop parameters.
  2. Step 2: Identify error

    The code lacks parentheses around '$i = 0; $i < 3; $i++'.
  3. Final Answer:

    Missing parentheses around the for loop parameters -> Option D
  4. Quick Check:

    For loops need parentheses [OK]
Quick Trick: For loops require parentheses [OK]
Common Mistakes:
  • Omitting parentheses in for loops
  • Confusing semicolon placement
  • Misusing braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes