Search code examples
c#do-whiledo-loops

How can i make patterns using do while loops in C#


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

Question:

Using a do loop, draw the following pattern:

*   
**
***
****
*****

Solution

  • 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