do while Loop

Written by


Do While


Do-while loop is somewhat similar to the while loop, but there is a small difference between both of them, and the difference is the place where the condition is tested. In while loop the condition is tested at the top of the loop i.e. the condition is tested before executing any statement inside the loop whereas in the do while loop the condition is tested at the bottom of the loop i.e. first the statements are executed then the condition will be tested. This means that if the condition is false then also the statement will be executed at least once.

The syntax of do-while loop is as follows:

     execute the statements;

Example :

 #include &ltstdio.h>
int main()
  int i=0;
    printf(“Value of i is: %d\n”, i);
  }while (j<=5);
  return 0;

Output :

Value of i is: 0
Value of i is: 1
Value of i is: 2
Value of i is: 3
Value of i is: 4
Value of i is: 5
do while Loop