Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

How to differentiate while and do while statement? 
The key difference b/n while and do while statement is that:

1.In while first checked the condition after that loop is executed. Where as in do while loop is executed at least one time when ever condition is true or false.

2.Syntax for while loop:
    
while (condition checked)
{
  //block of code
}

Syntax for do while loop:
do
{
   //block of code
} while (condition checked);

3.Example:
Use of while:
This program counts from 1 to 100.
#include <stdio.h>
int main(void)
{
    int count = 1;
    while (count <= 100)
    {
       printf("%d
",count);
       count += 1; // statement
    }
return 0;
}
Use of do while:
include <stdio.h>
int main(void)
{
    int val, r_digit;
    printf(�Enter a number to be reversed.
�);
    scanf(�%d�, &val);
    do
    {
       r_digit = val % 10;
       printf(�%d�, r_digit);
       val = val / 10;
    } while (val != 0);
printf(�
�);
return 0;
}