Bird
0
0

Identify the error in this do-while loop code snippet:

medium📝 Debug Q14 of 15
C - Loops
Identify the error in this do-while loop code snippet:
int x = 5;
do {
    printf("%d", x);
    x--;
} while x > 0;
AThe loop condition should be inside braces.
BMissing parentheses around the while condition.
CVariable x is not initialized.
DMissing semicolon after the do block.
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of the while condition

    The while condition must be enclosed in parentheses, like while (x > 0);.
  2. Step 2: Identify the error in the code

    The code has while x > 0; missing parentheses, causing a syntax error.
  3. Final Answer:

    Missing parentheses around the while condition. -> Option B
  4. Quick Check:

    while(condition) needs parentheses = D [OK]
Quick Trick: Always put condition in parentheses after while [OK]
Common Mistakes:
  • Omitting parentheses in while condition
  • Forgetting semicolon after while statement
  • Misplacing braces around condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes