Search code examples
c#loopsfor-loopreverse

How to reverse for loop in c# for string type ? i need to remove one character each iteration


static void Task()
{
    string x = "*";
    for (int i = 0; i < 4; i++)
    {
        Console.WriteLine(x);
        x += "*";
    }
}

it output

*
**
***
****

how damn reverse it only with "for" loop ? especially with included loop...


Solution

  • it's ok now

    for (int i = 4; i > 0; i--)
                {
                    for (int j = 1; j <= i; j++)
                        Console.Write("*");
                    Console.WriteLine();
                }