What are the do-while Loop in C Language ??? with Free Notes

What are the do-while Loop ???

do-while Loop is another repetitive control structure provided by C. It is almost same as that of while loop and is used for the problems where it is not known in advance that how may times a statement block will be executed.

Since the Condition is tested after the execution of the loop, it is also known as post-test Loop. This Loop is executed at least once.

Syntax,

Here is the syntax of the do-while Loop to understand the concept,

do {
    // code block to execute
} while (condition);

This syntax explains, the code block which is inside the loop is executes first and then the condition will be checked. If the first condition is true, the loop continues to executes.

C Language Notes

Example: do-while Loop

Now Let’s understand this concept with the example how it works,

#include <stdio.h>

int main() {
    // Do-While loop example
    int i = 1;
    do {
        printf("Iteration %d\n", i);
        i++;
    } while (i <= 5);

    return 0;
}

Note :

The statement block is executed as long as the condition remains true. As soon as condition becomes false, the control leaves the loop and goes to the next immediate statement after the while.

Leave a Comment

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

Scroll to Top