Given: for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(i==1 && j==1) break; } } What is the value of i after the outer loop completes?
Correct: the outer loop completes all three iterations, ending with i=3.
Why this answer
The outer loop variable `i` increments from 0 to 2. When `i` is 1 and `j` is 1, the `break` statement exits only the inner `for` loop, not the outer loop. The outer loop continues to its next iteration, incrementing `i` to 2, then to 3.
When `i` becomes 3, the outer loop condition `i < 3` fails, so the loop terminates. Thus, after the outer loop completes, `i` is 3.
Exam trap
The trap here is that candidates often mistakenly think `break` exits all nested loops or that the loop variable retains the value at the time of the break, leading them to choose 1 or 2 instead of recognizing the outer loop continues to completion.
How to eliminate wrong answers
Option A is wrong because `i` is never 1 after the outer loop finishes; the loop increments `i` to 2 and then 3 before exiting. Option B is wrong because `i` becomes 2 during the loop but continues to increment to 3 when the condition fails. Option C is wrong because `i` never reaches 4; the loop condition `i < 3` stops at 3.