do-while loop in c

do-while loop in c, first executes statements, then check the test condition. It means do while loop executes statements at least once, if test condition is false. It is an exit control loop.

Syntax

initialization;
do{
     // statements
     // iteration;
}while(condition);
initializationThe start value from where the do while loop starts.
conditionIt specifies the number of times do while loop will repeat statements.
iterationIt continue the loop, by increasing value to continue the loop cycle.

Example

#include<stdio.h>

void main()
{
   int i = 0; // initialization
    do {
        printf("%d ", i);
        i++; // iteration;
    } while (i < 5); //condition
}

Explanation

  1. int i = 0; is initialization, the value from where do while loop starts.
  2. i++; is iteration. It continues do while loop cycle.
  3. while (i < 5); It is test condition, It checks the condition, and executes the loop.