C++ do while loops - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Saturday 7 October 2017

C++ do while loops

C++ do while loops





C++ do while loops is very similar to the while loops, but it always executes the code block at least once and further more as long as the condition remains true. This is exit-controlled loop.
The basic format of do while loop statement is:
Syntax:
do
{
   statement(s);

}while( condition );
Figure – Flowchart of do while loop:
cplusplus-do-while

Example of a C++ Program to Demonstrate do while loop

Example:
#include <iostream>
using namespace std;
 
int main ()
{
   /* local variable Initialization */
   int n = 1,times=0;

   /* do-while loops execution */
   do
   {
      cout << "C++ do while loops: " << n <<endl;
      n++;
   }while( n <= times );
   return 0;
}
Program Output:
cplusplus-do-while

No comments:

Post a Comment

Post Top Ad