do...while Loop in C Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report C do...while loop is a type of loop that executes a code block until the given condition is satisfied. Unlike the while loop, which checks the condition before executing the loop, the do...while loop checks the condition after executing the code block, ensuring that the code inside the loop is executed at least once, even if the condition is false from the start.Example: C #include <stdio.h> int main() { // Loop variable declaration and initialization int i = 0; // do while loop do { printf("Geeks\n"); i++; } while (i < 3); return 0; } OutputGeeks Geeks Geeks Explanation: The do...while loop in this C program prints "Geeks" three times by executing the loop body at least once and continuing until the condition i < 3 becomes false.Syntax C do { // Body of the loop // Update expression } while (condition); where,condition: The loop condition which will decide the number of times the loop runs.update expression: The expression that updates the condition to move it towards the loop end in each repetition.Working of do...while LoopLet's understand the working of do while loop using the below flowchart.Flowchart of do...while Loop in CWhen the program control comes to the do...while loop, the body of the loop is executed first and then the test condition/expression is checked, unlike other loops where the test condition is checked first. Due to this property, the do...while loop is also called exit controlled or post-tested loop. When the test condition is evaluated as true, the program control goes to the start of the loop and the body is executed once more.The above process repeats till the test condition is true.When the test condition is evaluated as false, the program controls move on to the next statements after the do...while loop.The initialization and updation is not a part of the do...while loop syntax. We have to do that explicitly before and in the loop respectively.Examples of do while LoopThe below programs demonstrate how to use the do while loops in C programs in different situations:do...while Loop for False Condition C #include <stdbool.h> #include <stdio.h> int main() { // Declaring a false variable bool c = false; do { printf("This is loop body."); // False condition } while (c); return 0; } OutputThis is loop body.Explanation: As we can see, the body of the loop is executed even if the condition was false from the start.Print Matrix using do-while loopWe can also nest one do...while loop into another loop (called nested loops). This helps in printing multidimensional structures such as matrices. C #include <stdio.h> int main() { // Declaring loop variables int i = 0, j; int c = 0; // Outer loop starts do { j = 0; // inner loop starts do { printf("%d ", c++); j++; } while (j < 3); printf("\n"); i++; } while (i < 3); return 0; } Output0 1 2 3 4 5 6 7 8 Difference between while and do...while LoopThe following table lists the important differences between the while and do...while Loop .while Loopdo...while LoopThe test condition is checked before the loop body is executed.The test condition is checked after executing the body.When the condition is false, the body is not executed not even once.The body of the do...while loop is executed at least once even when the condition is false.It is a type of pre-tested or entry-controlled loop.It is a type of post-tested or exit-controlled loop.Semicolon is not required.Semicolon is required at the end. Do While Loop in C Visit Course Comment More infoAdvertise with us H harsh_shokeen Follow Improve Article Tags : C Language Explore C Programming Language Tutorial 4 min read C BasicsC Language Introduction 6 min read Features of C Programming Language 3 min read C Programming Language Standard 6 min read C Hello World Program 1 min read Compiling a C Program: Behind the Scenes 4 min read C Comments 3 min read Tokens in C 4 min read Keywords in C 2 min read C Variables and ConstantsC Variables 4 min read Constants in C 4 min read Const Qualifier in C 6 min read Different ways to declare variable as constant in C 2 min read Scope rules in C 5 min read Internal Linkage and External Linkage in C 4 min read Global Variables in C 3 min read C Data TypesData Types in C 5 min read Literals in C 4 min read Escape Sequence in C 5 min read bool in C 5 min read Integer Promotions in C 2 min read Character Arithmetic in C 2 min read Type Conversion in C 4 min read C Input/OutputBasic Input and Output in C 4 min read Format Specifiers in C 5 min read printf in C 5 min read scanf in C 3 min read Scansets in C 2 min read Formatted and Unformatted Input/Output in C 6 min read C OperatorsOperators in C 11 min read Arithmetic Operators in C 5 min read Unary Operators in C 5 min read Relational Operators in C 4 min read Bitwise Operators in C 6 min read C Logical Operators 4 min read Assignment Operators in C 4 min read Increment and Decrement Operators in C 4 min read Conditional or Ternary Operator (?:) in C 3 min read sizeof operator in C 3 min read Operator Precedence and Associativity in C 7 min read C Control Statements Decision-MakingDecision Making in C (if , if..else, Nested if, if-else-if ) 7 min read C - if Statement 4 min read C if else Statement 3 min read C if , else if ladder 4 min read Switch Statement in C 5 min read Using Range in switch Case in C 2 min read C - Loops 6 min read C for Loop 4 min read while Loop in C 5 min read do...while Loop in C 4 min read For vs. While 4 min read Continue Statement in C 4 min read Break Statement in C 5 min read goto Statement in C 4 min read C FunctionsC Functions 6 min read User-Defined Function in C 6 min read Parameter Passing Techniques in C 3 min read Function Prototype in C 4 min read How can I return multiple values from a function? 3 min read main Function in C 5 min read Implicit Return Type int in C 2 min read Callbacks in C 4 min read Nested Functions in C 4 min read Variadic Functions in C 5 min read _Noreturn function specifier in C 2 min read Predefined Identifier __func__ in C 2 min read C Library math.h Functions 6 min read C Arrays & StringsC Arrays 7 min read Properties of Array in C 7 min read Multidimensional Arrays in C - 2D and 3D Arrays 8 min read Initialization of Multidimensional Array in C 4 min read Pass Array to Functions in C 3 min read How to pass a 2D array as a parameter in C? 3 min read What are the data types for which it is not possible to create an array? 2 min read How to pass an array by value in C ? 2 min read Strings in C 6 min read Array of Strings in C 3 min read What is the difference between single quoted and double quoted declaration of char array? 2 min read C String Functions 6 min read C PointersC Pointers 9 min read Pointer Arithmetics in C with Examples 10 min read C - Pointer to Pointer (Double Pointer) 5 min read Function Pointer in C 6 min read How to Declare a Pointer to a Function? 2 min read Pointer to an Array | Array Pointer 5 min read Difference between constant pointer, pointers to constant, and constant pointers to constants 3 min read Pointer vs Array in C 1 min read Dangling, Void , Null and Wild Pointers in C 6 min read Near, Far and Huge Pointers in C 4 min read restrict Keyword in C 3 min read Like