Bird
0
0

Identify the error in this loop:

medium📝 Debug Q6 of 15
C - Loops
Identify the error in this loop:
int i = 0;
while (i < 5);
{
    printf("%d ", i);
    i++;
}
AExtra semicolon after while condition causes infinite loop.
BMissing braces around loop body.
CVariable i is not initialized.
DIncorrect printf format specifier.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop syntax

    Semicolon after while (i < 5); ends loop prematurely, creating an empty loop.
  2. Step 2: Effect of extra semicolon

    The block after is not part of loop, causing infinite loop or unexpected behavior.
  3. Final Answer:

    Extra semicolon after while condition causes infinite loop. -> Option A
  4. Quick Check:

    Semicolon after while condition breaks loop flow [OK]
Quick Trick: No semicolon immediately after while(condition) [OK]
Common Mistakes:
  • Ignoring semicolon after while
  • Assuming braces fix semicolon issue
  • Thinking variable initialization causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes