Do While Loop in C Programming

Do While Loop

This construct is also used for looping. In this case the loop condition is tested at the end of the body of the loop. Hence the loop is executed at least one. The do-while is an unpopular area of the language, most programmers tries to use the straight while if it is possible.

Syntax of do while loop is

        do 
         { 
         Statement 1; 
         Statement 2;
         
        ................... 
         Statement n;
         } 
        while(expression);

Here the block of statement following the do is executed without any condition check. After this expression is evaluated and if it is true the block of statement in the body of the loop is executed again. Thus the block of statement is repeatedly executed till the expression is evaluated to false.

do-while construct is not used as often as the while loops or for loops in normal case of iteration but there are situation where a loop is to be executed at least one, in such cases this construction is very useful.

The following example illustrates the use of do-while loop.

Ready to get started?

Ready to embark on your journey into the world of C programming? Our comprehensive course provides the perfect starting point for learners of all levels. With engaging lessons, hands-on exercises, and expert guidance, you'll gain the skills and confidence needed to excel in this fundamental programming language. Let's dive in and unlock the endless possibilities of C programming together!