MCQ Single Best Answer Moderate

QIn which scenario would you use a while loop instead of a for loop?

ID: #23086 While Loop in Programming Language 86 views
Question Info
#23086Q ID
ModerateDifficulty
While Loop in Programming LanguageTopic

Choose the Best Option

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

  • A When the number of iterations is known
  • B When you want to loop over a collection
  • C When the number of iterations is unknown
  • D When you want to terminate the loop after a fixed number of iterations
Correct Answer: Option C

Explanation

A while loop is typically used when the number of iterations is unknown or depends on a condition that may change during execution. In contrast, a for loop is usually preferred when the number of iterations is known in advance, such as when iterating through a fixed range. A while loop continues executing as long as its condition remains true, making it ideal for situations where you are waiting for some event to occur or processing input that may vary in length or content.

Share This Question

Challenge a friend or share with your study group.