Bird
0
0

Consider this code:

hard📝 Application Q9 of 15
C - Loops
Consider this code:
int i = 0;
do {
    if (i == 2) break;
    printf("%d ", i);
    i++;
} while (i < 5);

What is the output?
A0 1
B0 1 2
C0 1 2 3 4
DInfinite loop
Step-by-Step Solution
Solution:
  1. Step 1: Trace loop with break

    i starts at 0, prints 0, increments to 1, prints 1, increments to 2.
  2. Step 2: Break at i == 2

    When i == 2, break exits loop before printing 2.
  3. Final Answer:

    0 1 -> Option A
  4. Quick Check:

    Break stops loop before printing 2 [OK]
Quick Trick: Break exits loop immediately [OK]
Common Mistakes:
  • Including 2 in output mistakenly
  • Ignoring break statement
  • Assuming loop runs full 5 times

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes