Bird
0
0

Identify the problem in this PHP code:

medium📝 Debug Q7 of 15
PHP - Loops

Identify the problem in this PHP code:

for ($i = 0; $i < 2; $i++) {
    for ($j = 0; $j < 2; $j++) {
        if ($j == 1) continue 3;
        echo "$i$j ";
    }
}
Acontinue 3 behaves like continue 1
Bcontinue 3 is invalid because only 2 nested loops exist
Ccontinue 3 skips all loops correctly
DNo problem, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check number of nested loops

    There are only 2 nested loops: outer and inner.
  2. Step 2: Validate continue level number

    continue 3 tries to skip 3 levels, which is invalid and causes a fatal error.
  3. Final Answer:

    continue 3 is invalid because only 2 nested loops exist -> Option B
  4. Quick Check:

    continue n > nested loops = error [OK]
Quick Trick: continue n must not exceed nested loop depth [OK]
Common Mistakes:
  • Using continue 3 with only 2 loops
  • Assuming continue 3 skips all loops safely
  • Ignoring PHP error on invalid continue level

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes