Do While Loop

1
2
3
4
5
6
7
8
int x = 20, y = 2;
do
{
       x -= x - 2;
       y += 4;
       cout << x << " ";
}while ( y <= 16);
      cout << ++x << "" << y << endl;



1
2
3
4
5
6
7
8
9
int x = 20, y = 2;
do
{
    x -= x-2;
    y += 4;
    cout << x << "";
}while (y <= 16);
cout << ++x << "" << y << endl;

How do I managed such qns? Tks.
Last edited on
Please explain what does "qns" means? (Sorry, I'm not English)
Sorry. I am actually refering to the do... while loop code. I am figuring out how to solve it w/o using compiler.
If I explain your code that I get the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int x = 20, y = 2;
do
{
    x = x - (x-2); // x gets 20 - (20 - 2)
    y = y + 4; // y is assigned value 6
    cout << x << "";
}while (y <= 16); // after first itaration x gets 2, y gets 6
x = x + 1;
cout << x << "" << y << endl;

You could track the iterations till the end.


Topic archived. No new replies allowed.