Do while Loop In C++

Card image cap

Do while Loop ?

Do-while loop is a variant of while loop where the condition isn't checked at the top but at the end of the loop, known as exit controlled loop. This means statements inside do-while loop are executed at least once and exits the loop when the condition becoms false or break statement is used. The condition to be checked can be changed inside the loop as well.


How do-while loop works?

First, the statements inside loop execute and then the condition gets evaluated, if,the condition returns true then the control jumps to the “do” for further repeated execution of it, this happens repeatedly until the condition returns false. Once condition returns false control jumps to the next statement in the program after do-while.

Syntax :

Card image cap

Example 1:



Output :

   1
   2
   3
   4
   5
Card image cap