How to use do-while loop in C Programming

 

Do-while loop is also a type of repetition structure used to repeat statement(s) for certain number of times. The major difference between while and do while loop is that in do while loop the loop termination condition is checked after the execution of loop body whereas in while loop the loop termination condition is checked before the execution of loop body. Do-while loop at least runs one time no matter if the loop termination condition is true or false. Following simple program explains how to use do-while repetition structure (also called as do-while loop) to print numbers from 1-10.
#include <stdio.h>

int main(void){
   // do-while loop is a type of repetition structure in C programming. In any loop you need to fulfill following 4        conditions
   int i; // 1st condition: define control variable
   i = 1; // 2nd condition: assign initial value to control variable
   do{
      printf("%d\n", i);
      i++; // 4th condition: increment/decrement control variable
   }while(i<=10); // 3rd condition: define loop termination condition

   return 0;
}

One Reply to “How to use do-while loop in C Programming”

Leave a Reply

Your email address will not be published. Required fields are marked *