Bird
0
0

Consider the nested loops below. What will be the output?

hard📝 Application Q15 of 15
C - Loop Control Statements

Consider the nested loops below. What will be the output?

for(int i = 1; i <= 3; i++) {
    for(int j = 1; j <= 3; j++) {
        if(j == 2) {
            break;
        }
        printf("%d%d ", i, j);
    }
}
A13 12 11
B11 21 31
C11 12 13 21 22 23 31 32 33
D11 12 21 22 31 32
Step-by-Step Solution
Solution:
  1. Step 1: Analyze inner loop behavior with break

    Inner loop runs j=1 to 3, but breaks when j==2, so only j=1 prints.
  2. Step 2: Trace all iterations

    For i=1, prints 11; i=2 prints 21; i=3 prints 31; each inner loop stops after j=1.
  3. Final Answer:

    11 21 31 -> Option B
  4. Quick Check:

    Break stops inner loop at j=2, prints only j=1 per i [OK]
Quick Trick: Break stops inner loop early, only first inner print per outer loop [OK]
Common Mistakes:
  • Assuming inner loop prints all j values
  • Confusing break effect on outer loop
  • Including j=2 prints

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes