0% found this document useful (0 votes)
545 views11 pages

C Do While Loop Statement

The do while loop is an exit-controlled loop that will execute at least once even if the loop condition is false. The syntax includes a do statement block followed by a while condition in parentheses and semicolon. Key aspects are that the condition is checked at the end of the loop so the do statement block will always run at least once. Several examples are provided to illustrate using do while loops to iterate from 1 to 10, sum user input numbers until a 0 is entered, and print numbers from 1 to 5.

Uploaded by

Acerlock My
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
545 views11 pages

C Do While Loop Statement

The do while loop is an exit-controlled loop that will execute at least once even if the loop condition is false. The syntax includes a do statement block followed by a while condition in parentheses and semicolon. Key aspects are that the condition is checked at the end of the loop so the do statement block will always run at least once. Several examples are provided to illustrate using do while loops to iterate from 1 to 10, sum user input numbers until a 0 is entered, and print numbers from 1 to 5.

Uploaded by

Acerlock My
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

C do while Loop Statement

Introduction
do-while loop is also an Iteration Statement in c
programming language.
do-while loop is an Exit Controlled loop because in dowhile loop the loop condition is checked at the end of the
loop and do-statement will execute at least once though the
condition is FALSE.
Thus, do-while loop is always executed at least once though
the condition is FALSE.

Syntax
do
{
statement 1;
statement2;
statement n;
}
while (loop condition) ;

Important Note:
The do-while loop must ends with a semicolon (;)
which is the important distinction from the ifstatement and while statement.
The do-while will continue to run until the loop
condition specified in while statement becomes
FALSE(0).

Do while loop Animation

http://www.cprogrammingexpert.com/C/Tutorial/control_statements/do_while_loop.aspx

Do while loop flow chart

Program
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i=1;
do{
printf("\n%d",i);
i++;
} while(i<=10);
getch();
return 0;
}

Program
#include<stdio.h>
#include<conio.h>
int main(void) {
clrscr();
int i,j,total;
total = 0;
do {
printf("Enter a number (0 to stop):\n ");
scanf("%d", &i);
printf("Enter the number again:\n ");
scanf("%d", &j);
if(i != j) {
printf("Number Mismatch\n");
continue;
}
total = total + i;
} while(i);
printf("Total Iterations are %d\n", total);
getch();
return 0;
}

Program
#include<stdio.h>
main( )
{
do
{
printf ( "Hello World \n") ;
} while ( 2 < 1 ) ;
getch();
}

Program

#include <stdio.h>
void main()
{
int x = 5;
int i = 0;
// using do while loop statement
do
{
i++;
printf("%d\n",i);
}while(i < x);
}

Output
1
2
3
4
5

You might also like