C do…while Loop

What is do while loop?

There might arise certain situations where it could be necessary to execute the body of the loop at first.  We will execute the body of the loop before the condition is set. In such a situation, we can use do while loop. Do while loop is also known as an exit controlled loop.

How does do while loop works?

Syntax:

initialization,
do{
the body of the loop;
increment or decrement;
}while(condition);
Flowchart:

Example of Do while loop:

Code:

The output of the above code will be displayed in the way below.

Output:

Enter a number:
5
Enter a number:
10
Total number after multiplication: 50

Things to remember:

  • In do while loop, the condition is checked at last.
  • The do while loop executes the body of the loop at least one time even if the condition is false. The body of the loop executes more when the condition is true.
  • Sometimes we also call do while loop as an exit controlled loop.
SHARE C do…while Loop

You may also like...

Leave a Reply

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

Share