Printing given word using Do While Loop in C++


This is a simple C++ program that uses a do-while loop to print a message three times. Here's a brief explanation of what the program does:

  • Declare an integer variable i and initialize it with 1.
  • Enter a do-while loop. This loop will execute at least once, regardless of whether the condition is true or false.
  • Inside the loop, print the message "Do while loop" using the cout statement. Then increment i by 1.
  • Check the condition i<4. If it is true, go back to step 3 and repeat the loop. If it is false, exit the loop.
  • End the program by returning 0.

Source Code

#include<iostream>
using namespace std;
int main()
{
    int i=1;
    do
    {
      cout<<"Do while loop"<<endl;
      i++;
    }
    while(i<4);
    return 0;
}
To download raw file Click Here

Output

Do while loop
Do while loop
Do while loop


Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples