C do-while loop is very similar to the while loop, but it always executes the code block at least once and as long as the condition remains true. It is an exit-controlled loop. This tutorial guides you on how to use "do while loop" in the C program.



The basic format of the do-while loop statement is:

Syntax:

do
{
   statement(s);

} while( condition );

Figure - Flowchart of the do-while loop:

Example of a C Program to Demonstrate do-while loop

Example:

#include<stdio.h>
 
int main ()
{
   /* local variable Initialization */
   int n = 1,times=5;

   /* do loops execution */
   do
   {
       printf("C do while loops: %d\n", n);
       n = n + 1;
   } while( n <= times );
 
   return 0;
}

Program Output:


C do while loops - Video Tutorial

Please watch this tutorial to understand "C do while loops" in more depth.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram