LearnFrenzy
Sign in Take a free test

C Loops · Find the Error · Question 4

Error: missing semicolon after do-while Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

The program below has a bug. Which statement correctly describes it?

main.c
#include <stdio.h>

int main(void) {
    int n = 3;
    do {
        printf("%d ", n);
        n--;
    } while (n > 0)
    printf("\n");
    return 0;
}
  • A do-while needs a for header
  • B A do-while statement must end with a semicolon after the condition Correct
  • C n-- must come before printf
  • D There is no bug
Correct Answer: Option B

Unlike while and for, a do-while ends with while (condition);. Without the semicolon the compiler reports a syntax error.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links