Do While Loop in C Programming

This is an exit controlled looping statement.
Sometimes, there is need to execute a block of statements first then to check condition later. At that time such type of a loop is used. In this, block of statements are executed first and then condition is checked.
Syntax:

do
{
	statements;
	(increment/decrement);
}while(condition);

In above syntax, the first block of statements are executed. At the end of loop, while statement is executed. If the resultant condition is true then program control goes to evaluate the body of a loop once again. This process continues till condition becomes true. When it becomes false, then the loop terminates.

Note: The while statement should be terminated with ; (semicolon).
Program :

/*  Program to demonstrate do while loop.
Creation Date : 09 Nov 2010 03:21:01 AM
Author :www.technoexam.com [Technowell, Sangli] */

#include <stdio.h>
#include <conio.h>

int main(void)
{
	int a;
	clrscr();
	a=1;
	do
	{
		printf("\n\t TechnoExam");  // 5 times
		a+=1;      // i.e. a = a + 1
	}while(a<=5);
	a=6;
	do
	{
		printf("\n\n\t Technowell");  // 1 time
		a+=1;      // i.e. a = a + 1
	}while(a<=5);
	getch();
	return 0;
}

Output :

 TechnoExam
 TechnoExam
 TechnoExam
 TechnoExam
 TechnoExam
 
 Technowell_

Leave A Comment

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