web analytics

Compare among the three loops. FOR loop VS WHILE loop VS DO….WHILE

Comparison among the three loop: 

The comparison among the three types of loops for loop, while loop and do….while loop is given below.

Suggested Reading:

  1. What are the entry controlled and exist controlled loops?
  2. What are the counter controlled and sentinel controlled loops?

No.
Topics
For loop
While loop
Do…while loop
01
Initialization of condition variable
In the parenthesis of the loop.
Before the loop.
Before the loop or in the body of the loop.
02
Test condition
Before the body of the loop.
Before the body of the loop.
After the body of the loop.
03
Updating the condition variable
After the first execution.
After the first execution.
After the first execution.
04
Type
Entry controlled loop.
Entry controlled loop.
Exit controlled loop.
05
Loop variable
Counter.
Counter.
Sentinel & counter
Also the following comparison of their structures completes the comparison.

For loop
While loop
Do….while loop
for(n = 1; n <= 10; n++)
{
========
========
}
n = 1;
while(n <=10)
{
==========
==========
n=n+1;
}
n = 1;
do
{
========
========
n = n + 1;
}
while(n<=10);
Thank you. Take a moment to share 🙏