C++ do while Statement

Introduction

The do-statement is similar to while-statement, but the condition comes after the body.

The code inside the do-statement is guaranteed to execute at least once.

The syntax is:

do { 
   // execute some code 
} while (condition); 

If we used the previous example, the code would be:

#include <iostream> 

int main() /*from w w w  . j  a v  a  2 s  . c  o  m*/
{ 
    int x = 0; 
    do 
    { 
        std::cout << "The value of x is: " << x << '\n'; 
        x++; 
    } while (x < 10); 
} 



PreviousNext

Related