C++ Do while loop

tutorial and example
tutorial and example

C++ do…while loop Statement

do…while loop is similar to a while loop, except that a do…while loop executes statement within doblock 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 semicolon (;).

Syntax

Working Process of do…while loop

  1. The statement inside the do body of loop is executed.
  2. Then the condition expression is checked.
  3. If the condition expression is true, the do body of 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.

Output