MCQ Single Best Answer Moderate

QWhat is the difference between a while loop and a do-while loop in C++?

ID: #23084 While Loop in Programming Language 106 views
Question Info
#23084Q ID
ModerateDifficulty
While Loop in Programming LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A A while loop always executes at least once
  • B A do-while loop checks the condition before the loop
  • C A do-while loop executes at least once
  • D A while loop can only be used with integers
Correct Answer: Option C

Explanation

The key difference between a while loop and a do-while loop is that a do-while loop guarantees that the loop's body will execute at least once, even if the condition is false from the beginning. In a while loop, the condition is checked first, so if the condition is false initially, the loop body may never execute. This makes the do-while loop useful for situations where you need the loop to run at least once, regardless of the condition. In contrast, a while loop only runs if the condition is true.

Share This Question

Challenge a friend or share with your study group.