MCQ Single Best Answer Moderate

QWhat is the key difference between a while loop and a do-while loop ?

ID: #23092 Do-While Loop in Programming Language 115 views
Question Info
#23092Q ID
ModerateDifficulty
Do-While Loop in Programming LanguageTopic

Choose the Best Option

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

  • A The while loop guarantees at least one execution
  • B The do-while loop guarantees at least one execution
  • C The while loop checks the condition after the loop
  • D Both loops are exactly the same
Correct Answer: Option B

Explanation

The fundamental difference between a while loop and a do-while loop is the placement of the condition check. In a while loop, the condition is checked before executing the loop body, so the body may not execute if the condition is false initially. In contrast, in a do-while loop, the condition is checked after the loop body, meaning the loop body will execute at least once, even if the condition is false from the start. This is a crucial feature when you want the loop to run at least once regardless of the condition's initial value, like asking for user input or prompting an action that must occur at least once.

Share This Question

Challenge a friend or share with your study group.