Question:

Which of the following is an entry control loop ?

Show Hint

Remember: `do-while` does the action first, then asks for permission to continue (exit-controlled). `while` and `for` ask for permission first, then do the action (entry-controlled).
  • For
  • While
  • Do-while
  • None of these
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Differentiate between entry-controlled and exit-controlled loops.

Entry-controlled loop (or pre-test loop): The loop's condition is checked \textit{before} the body of the loop is executed. If the condition is false initially, the loop body will never run.
Exit-controlled loop (or post-test loop): The loop's condition is checked \textit{after} the body of the loop has been executed. This guarantees the loop body runs at least once.

Step 2: Classify the loop types.

(A) For loop: Checks its condition before each iteration. It is an entry-controlled loop.
(B) While loop: Checks its condition before each iteration. It is an entry-controlled loop.
(C) Do-while loop: Executes the body once, and then checks the condition. It is an exit-controlled loop.
Both `for` and `while` are entry-controlled loops. In a multiple-choice context where only one can be selected, there might be ambiguity, but both fit the definition. If both are options, sometimes `while` is seen as the quintessential pre-test loop. However, both are correct.
Was this answer helpful?
0
0