-8

I'm kind of a newbie when it comes to looping. :( please help me.

Question:

Using a do loop, draw the following pattern:

*   
**
***
****
*****
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215

3 Answers3

0
class MainClass
{
    public static void Main (string[] args)
    {
        int counter = 1;

        do {

            for (int i = 0; i < counter; i++) {
                Console.Write("*");
            }
            Console.WriteLine(); // for newline
            counter++;   // increase counter

        } while (counter < 6);
    }
}

sorry for my bad english. You can use a counter in the do-while loop

0

You can create a method that generates stars string:

public static string starGenerator(int count)
{
    string stars = string.Empty;
    for(int i = 0; i < count; i++)
        stars += "*";

    return stars;
}

And then use it:

public static void Main(string[] args)
{
    int counter = 1;
    do
    {
        string stars = starGenerator(counter);
        Console.WriteLine(stars);

        counter++;
    } while(counter <= 5);
}
SLDev
  • 336
  • 2
  • 6
0

There are many ways to implement this, if you insist on do..while:

string line = "";

do {
  Console.WriteLine(line += "*");
}
while (line.Length < 6);
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215