Bird
0
0

Find the error in this PHP loop code:

medium📝 Debug Q14 of 15
PHP - Loops
Find the error in this PHP loop code:
for ($i = 0; $i < 5; $i++)
    echo $i
AMissing semicolon after echo statement
BIncorrect loop variable name
CLoop condition should be <= 5
Dfor loop cannot be used without braces
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax inside the loop

    The echo statement is missing a semicolon at the end.
  2. Step 2: Verify other parts of the loop

    Loop variable and condition are correct; braces are optional for single statements.
  3. Final Answer:

    Missing semicolon after echo statement -> Option A
  4. Quick Check:

    Missing semicolon = C [OK]
Quick Trick: Every PHP statement ends with a semicolon [OK]
Common Mistakes:
  • Forgetting semicolons after statements
  • Thinking braces are always required
  • Changing loop condition unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes