CodesJava

Easy learning with example program codes

C do while loop


C Do While Loop is a loop statement which is used to execute a block of code continuously as long as the condition of the loop is true, and stops only when the condition fails like other loop statements.

The unique feature of Do While loop is that it is used to execute a block of code at least once and then to repeat the actions as long as the specified condition is true.

 

Syntax:

do

{

    code to be executed;

}

while (condition);

 

Example 1: When the While condition is true

void main()
{
int i = 1;
 
do
{
printf ("%d", i);
i++;
}
while (i <= 10);
}

Output

12345678910

Example 2: When the While condition is false

void main()
{
int i = 11;
 
do
{
printf ("%d", i);
i++;
}
while (i <= 10);
}

Output

11
Posted in C   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki