Thursday 18 May 2017

Elements of programming-8




Do while loop:

 In while looping condition is checked at the entry of the loop.if the condition is false the loop will terminate even before the first iteration of loop. In while loop the condition is checked at the end of the loop. So there is a guarantee the loop will run at least one time Even if the condition is false.

Difference Between while and do-while loop.


While loop


Do-while loop

The condition checked at the entry of the loop

The condition is checked at the exit of the loop


Zero time execution is possible

The loop will run atleast ontime on any condition


 Example 

#include <stdio.h>
int main()
{
    int i=1;
 do
    {
        printf("%d\n",i);
        i++;
    }  while(i<=10);

    return 0;
}

Output:

Thankyou
-----Muthu karthikeyan,Madurai.