MCQ
Single Best Answer
Moderate
QHow can you avoid an infinite loop in a while loop?
ID: #23088
While Loop in Programming Language
84 views
Question Info
#23088Q ID
ModerateDifficulty
While Loop in Programming LanguageTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option B
Explanation
To avoid an infinite loop, it is important to ensure that the loop control variable changes with each iteration, which can be done by including an increment, decrement, or another modification inside the loop body. If the loop control variable does not change, the condition will never become false, leading to an infinite loop. The continue statement only skips the current iteration, and the exit() function is used to terminate the program, not just the loop.
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic