I'm kind of a newbie when it comes to looping. :( please help me.
Question:
Using a
do
loop, draw the following pattern:
*
**
***
****
*****
I'm kind of a newbie when it comes to looping. :( please help me.
Question:
Using a
do
loop, draw the following pattern:
*
**
***
****
*****
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
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);
}
There are many ways to implement this, if you insist on do..while
:
string line = "";
do {
Console.WriteLine(line += "*");
}
while (line.Length < 6);