Do While Loop in C

Do While Loop in C programming will execute the code block once, before checking if the condition is true, and repeat a specific block of code until the condition is met.

Do While Loop


do
{
this;
and this;
and this;
and this;
}
while(this condition is true);

Program Printing 1 to 10 using Do While Loop

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 1;
do //doing then Statement.
{
printf("%d \n", a);
a++; //adding 1 to 'a'.
}
while(a <= 10); //loop from 0 to 10.
getch();
}
Output
1
2
3
4
5
6
7
8
9
10

Program Password using Do While Loop

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int val;
do //executing process.
{
printf("Please Enter Password: ");
scanf("%d", &val); //user enter value storing in 'val'.
}
while(val != 54265); //loop stop when 'val' value Equal to 54265.
printf("Password Correct!");
getch();
}
Output
Please Enter Password: 3434
Please Enter Password: 23
Please Enter Password: 54265
Password Correct!