C++ do…while loop Statement

do…while loop is similar to a while loop, except that a do…while loop executes statement within do block first and then check the condition of while. It guaranteed to execute at least one time of statement.

In do while loop, while statement (loop) ends with a semicolon (;).


Working Process of do…while loop

  1. The statement inside the do body of the loop is executed.
  2. Then the condition expression is checked.
  3. If the condition expression is true, then do body of the loop is executed. This process continues until the condition expression becomes false.
  4. When the condition expression is false, do…while loop is terminated.


C++ do…while loop Example

This program print counting from 1 to 10.


Pin It on Pinterest

Share This