Navratri Sale: Get Upto 30% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now
Understanding do...while loop in C

Understanding do...while loop in C

27 May 2024
Beginner
1.31K Views
5 min read
Learn via Video Course & by Doing Hands-on Labs

Free C Programming Online Course With Certificate

do...while Loop in C: An Overview

The do-while loop is similar to the while loop. But this loop will execute the code block once, before checking if the condition is true. Afterward, this loop will repeat itself as long as the condition is true.

In this C Tutorial, we will explore more about the do...while loop which will include what is do...while in C, do...while loop in c programming with example, and the syntax of do...while loop in C. 

Read More - Top 50 C Interview Questions and Answers

Types of Loop in C

Let’s get into the three types of loops used in C programming.
  1. for loop
  2. while loop
  3. do while loop

But right now we are going to focus on only Do while Loop, So let's discuss it.

What is a do...while loop?

Do While is an exit-controlled loop. It prints the output at least once before checking the condition. Afterwards, the condition is checked and the execution of the loop begins.

Flowchart :

  

Syntax

do{
//code to be executed
}while(test condition);
  • The body of the loop executes before checking the condition.
  • If the test condition is true, the loop body executes again.
  • Again the test condition is evaluated.
  • The process repeats until the test condition becomes false.

Example: do...while loop in C

Let's elaborate do-while loop in C Compiler.

#include <stdio.h>
int main() 
{
 int i = 0;
 do {
 printf("%d\n", i+1);
 i++;
 }
 while (i < 10);
 return 0;
}
  • The above code prints numbers from 1 to 10 using the do while loop in C.
  • It prints 1 before checking if i less than 10.
  • It checks the condition i<10 and executes until i becomes 10

Output

1
2
3
4
5
6
7
8
9
10
Conclusion:
So we explored What is Do while in C, and Do While loop in C programming with example, the syntax of the Do while loop in C. Master your coding base in C programming to the next level by pursuing a C Programming Course, which will validate your expertise in loops and other important concepts.

FAQs

Q1. What is a do-while loop?

It is used to loop through a code until the given condition is satisfied.

Q2. Why is it called a do-while loop?

Because,it executes the body of the loop and then validates the condition or test expression

Q3. What are the advantages of do while loop?

  • The structure of a do-while loop is simple and easy to understand anyone.
  • The code inside a do-while loop is always executed at least once in life, regardless of the condition.
  • The code inside a do-while loop will continue to execute until the condition is True.

Share Article

Live Classes Schedule

Our learn-by-building-project method enables you to build practical/coding experience that sticks. 95% of our learners say they have confidence and remember more when they learn by building real world projects.
Full-Stack .NET Developer Certification TrainingOct 13SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details
ASP.NET Core ProjectOct 19SAT, SUN
Filling Fast
10:00AM to 12:00PM (IST)
Get Details
Advanced Full-Stack .NET Developer Certification TrainingOct 20SAT, SUN
Filling Fast
09:30AM to 11:30AM (IST)
Get Details
.NET Solution Architect Certification TrainingOct 20SAT, SUN
Filling Fast
05:30PM to 07:30PM (IST)
Get Details
.NET Microservices Certification TrainingOct 20SAT, SUN
Filling Fast
05:30PM to 07:30PM (IST)
Get Details
ASP.NET Core Certification TrainingOct 20SAT, SUN
Filling Fast
09:30AM to 11:30AM (IST)
Get Details
Microsoft Azure Cloud Architect with AINov 10SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details

Can't find convenient schedule? Let us know

About Author
Sakshi Dhameja (Author and Mentor)

She is passionate about different technologies like JavaScript, React, HTML, CSS, Node.js etc. and likes to share knowledge with the developer community. She holds strong learning skills in keeping herself updated with the changing technologies in her area as well as other technologies like Core Java, Python and Cloud.

Accept cookies & close this