Which of the following is an exit controlled loop?
a) for loop
b) while loop
c) do-while loop
d) if-else loop
Answer:
c) do-while loop
Explanation:
A do-while
loop in C is an exit-controlled loop, meaning the loop’s body is executed at least once before the condition is tested. This is different from for
and while
loops, which are entry-controlled, meaning the condition is checked before entering the loop. do-while
is useful when the loop body needs to be executed at least once, regardless of the condition.
Understanding the differences between entry and exit-controlled loops is important for choosing the right loop structure based on the specific needs of your program.