C – Do While Loop

C – Do While Loop 2017-08-05T20:14:27+00:00

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 loop 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.

C – DO – WHILE EXAMPLE PROGRAM :

Output :

1

2

3

4

5

Prev Next