How I can print my name 100 times without using loops in C#? Any clues? I have already tried to print number 1 to 100 without using loops but how I can do it with string(my name)?
Thank you in advance!
How I can print my name 100 times without using loops in C#? Any clues? I have already tried to print number 1 to 100 without using loops but how I can do it with string(my name)?
Thank you in advance!
I guess it comes down to what your definition of loop is.
Recursion
public static void Recurse(int count)
{
if(count == 0) return;
Console.WriteLine("Bobo");
Recurse(count - 1);
}
Fancy pants linq
Enumerable.Range(0, 100)
.ToList()
.ForEach(x => Console.WriteLine("bobo"));
or supplied by MKR
Console.Write(string.Concat(Enumerable.Repeat("Robo\n", 100))
Note : this still loops underneath, via an iterator method
I'm a kid from the 80's goto
public static void Goto(int count)
{
startLoop:
if (count-- <= 0)return;
Console.WriteLine("Bobo");
goto startLoop;
}
2 finger Copy/Paste loop
Console.WriteLine("Bobo");
Console.WriteLine("Bobo");
Console.WriteLine("Bobo");
Console.WriteLine("Bobo");
...