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
{
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.
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).
Basic Financial terms in Corporate and Mathematical Finance |
Selection of assets, risk and return, and portfolio analysis |
View the online notes for Financial Mathematics (CT1) |
Learn Financial Computing with C++ step by step |