Cpp - do while statement

Introduction

The do while loop is controlled by its footer.

The controlling expression is evaluated after executing the first loop.

This results in the loop body being performed at least once.

do 
   statement 
while( expression); 

When a do-while loop is executed, the loop body is processed first.

The do-while loop must be followed by a semicolon.

Demo

#include <iostream> 
using namespace std; 

const long delay = 10000000L; 

int main() /*from   w  w w .  ja v a2 s. c o  m*/
{ 
    int tic; 
    cout << "\nHow often should the tone be output? "; 
    cin >> tic; 

    do 
    { 
       for( long i = 0; i < delay; ++i ) 
           ; 
       cout << "Now the tone!\a" << endl; 
    } 
    while( --tic > 0 ); 

    cout << "End of the acoustic interlude!\n"; 

    return 0; 
}

Result

Related Topic