Hello readers, in this article we will discuss entry controlled loop and exit controlled loop in a very easy language so that all the confusion can be solved.
 

Entry-Controlled Loop

As the name suggests, Entry-Controlled Loop is the kind of loop that is controlled in entry i.e. the condition is checked before entering into the loop body. In this type of loop, we check the condition of the loop first and then iterate the loop, if the condition is not satisfied then the loop will not execute. Let’s take an example program in C that looks like the following.
 
 
#include <stdio.h>
#include <conio.h>
void main()
{
    for(int i=1; i<=10; i++)
{
printf(“%d”, i);
}
getch();
}
 
 
Here in this program example, since the condition is satisfied perfectly, the loop will iterate normally. But in the same case if the program was like the following:
 
#include <stdio.h>
#include <conio.h>
void main()
{
for(int i=100; i<=10; i++)
{
    printf(“%d”, i);
}
getch();
}
 
Here, since the condition is not satisfied, the loop will not execute. It is because the program is checking for the condition before entering into the loop body. for…loop and while…loop is the example of entry controlled loop.
 

Exit-Controlled Loop

As the name suggests, exit-controlled, in this type of loop, the loop body will first be executed once and then the condition will be checked i.e. the loop is controlled during the exit of the program. In this type of loop, if the condition is not correct then also the loop will iterate once. Let’s consider a program example like the following:
 
 
#include <stdio.h>
#include <conio.h>
void main()
{
int i=1;
do
{
    printf(“%d”, i);
    i++;
}while(i<=10);
getch();
}
 
 
Here, the condition is satisfied so the loop will execute normally as it should. But on the other hand, let’s consider another program example:
 
#include <stdio.h>
#include <conio.h>
void main()
{
int i=100;
do
{
    printf(“%d”, i);
    i++;
}while(i<=10);
getch();
}
 
Here, in this program example, the condition is not satisfied. Although the loop will execute for once since the condition is checked after the loop body is executed. do…while loop is the example of an exit-controlled loop.
 

Difference Between Entry Controlled Loop and Exit Controlled Loop

 
Entry Controlled LoopExit Controlled Loop
Loop will not execute if the condition is false.Loop will execute once even if the condition is false.
for loop and while loop is the example of entry controlled loop.a do-while loop is an example of an exit-controlled loop.
Condition is checked first and then the loop body is accessed.The Loop body is accessed and then the condition is checked.
Entry-controlled loops are used in case we have to check conditions before executing the loop.Exit Controlled loops are used in case we have to execute the loop first and then check the condition.
Example:

for(int i=100; i<=10; i++){
printf(“%d”, i);
}
Example:

do
{
printf(“%d”, i);
i++;
}while(i<=10);
Entry Controlled Loop and Exit Controlled loop Difference

I think this meme describes the basic difference between entry controlled and exit controlled loops.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *