Header Ads Widget

do - while Loop in C

do
{
    Body of loop
    ............
}while( test condition);

Here test condition is at the end of loop. When body of loop is executed after that do-while  loop tests the condition. This means that do-while loop always executes at least once, even if the condition fails for first time. If  the condition is true then again the loop body is executed and this process continues until condition becomes false.

Example : Program in C to count the digits in any number.
#include <stdio.h>
void main()
{
int num, count = 0;
scanf("%d",&num);
do
{
   num= num/10;
   count ++;   
}while(num > 0);
printf("There are  %d digits in %d", count , num);
}

Post a Comment

0 Comments