Convert nested for loop to nested do while loop

I am trying to convert a nested for loop that prints a right triangle into a nested do while loop, and I'm stumped after over 3 hours.

Here is the nested for loop I came up with.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;

int main()
{
  int line;
  int star;

  for (line = 1; line < 11; line++)
  {
    for (star = 1; star <= line; star++)
         cout << '*';
    cout << endl;
   }

return 0;
}


And following is one of my many failed attempts to convert to a nested do while
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
using namespace std;

int main()
{
  int line = 1;
  int star = 1;

  do
  {
    cout << '*';
    star++;
   do
   {
     cout << endl;
     line++;
    }while (star>line);
  }while (line<11);
 
return 0;
}


Thanks for the help.
Holy cow, I finally got it!

I realized one of the issues was that I needed to declare the star variable within the loop. Well, and the rest was a general mess too. Maybe one day I'll be able to explain to myself and others... :)
Topic archived. No new replies allowed.