Bird
0
0

Find the error in this loop code:

medium📝 Debug Q6 of 15
C - Loops
Find the error in this loop code:
int i = 0;
while(i < 5)
    printf("%d", i);
    i++;
AMissing semicolon after printf
BVariable i is not declared
CCondition should be i <= 5
Di++ is outside the loop block and never runs inside loop
Step-by-Step Solution
Solution:
  1. Step 1: Check loop body braces

    Without braces, only the first statement after while is inside loop.
  2. Step 2: Identify effect on i++

    i++ is outside loop, so i never increments inside loop, causing infinite loop.
  3. Final Answer:

    i++ is outside the loop block and never runs inside loop -> Option D
  4. Quick Check:

    Loop body needs braces for multiple statements [OK]
Quick Trick: Use braces to include all statements inside loop [OK]
Common Mistakes:
  • Assuming i++ runs inside loop
  • Changing condition unnecessarily
  • Ignoring braces importance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes