Bird
0
0

In PHP nested loops, how do you skip the current iteration of the outer loop from within the inner loop?

easy📝 Conceptual Q2 of 15
PHP - Loops

In PHP nested loops, how do you skip the current iteration of the outer loop from within the inner loop?

AUse <code>break 2;</code> inside the inner loop
BUse <code>continue;</code> inside the inner loop
CUse <code>continue 2;</code> inside the inner loop
DUse <code>continue 1;</code> inside the inner loop
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop levels

    In nested loops, continue can take a numeric argument to specify how many levels of loops to skip.
  2. Step 2: Apply continue 2;

    Using continue 2; inside the inner loop skips the current iteration of the outer loop.
  3. Final Answer:

    Use continue 2; -> Option C
  4. Quick Check:

    Skipping outer loop iteration requires continue 2; [OK]
Quick Trick: Use continue with level number to skip outer loops [OK]
Common Mistakes:
  • Using continue without a number skips only inner loop
  • Using break instead of continue
  • Using continue with wrong level number

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes