The do - while Loop

The do - while loop in C++. Construction and Examples. The do - while loop is used when we have to run a program until a given condition is true.

Construction: The do - while loop

do
{
   Statement(s)
}
while (condition);


Q 1. Write a program in C++ using do - while loop, that take a number, and increase it 2 by 2, and ends before 30.

#include
using namespace std;
int main()
{
int a;
cout << "Enter a Number: " << endl;
cin >> a;
do
{
   a = a+2;
   cout << a << endl;
}
while (a<28);
}


In while condition we set a<28 so that it must not reach 30. Since it is adding 2 (a=a+2).

RELATED PAGES
- The for loop
- The while loop
- The do-while loop


Basic Financial Terms
Basic Financial terms in Corporate and Mathematical Finance
Financial Portfolio Analysis
Selection of assets, risk and return, and portfolio analysis
Financial Mathematics Notes
View the online notes for Financial Mathematics (CT1)
Financial Computing with C++
Learn Financial Computing with C++ step by step