-->

neb37:Differentiate between while and do.. while loop.

Differentiate between while and do.. while loop.
ans:
Following are differences between while and do...while loop




while
Do..while
1
It is called pre-testing loop.
it is called post-testing loop
2
It uses keyword ‘while’.
it uses keyword ‘do.. while’
3
Its syntax is
Initialization;
While(condition)
{
Statement;
Increment/decrement;
}
 Its syntax is
Initialization;
do
{
Statement;
Increment/decrement;
              }while(condition);
4
nothing will happen if the condition is false.
 even after false(condition), it will run at least once.
5
Its flowchart is



Its flowchart is


6
example is
Int i=1;
While(i<=5)
{
Printf(“%d”,i);
I++;
}
 example is
Int i=1;
do
{
Printf(“%d”,i);
I++;
}while(i<=5);

No comments:

Post a Comment