i want to write a shape with " \* " and " | " the shape is below.
The program must take height and width from user.Width is column number without ' | '.I tried to write but confused.My code sometimes works great and sometimes being stupid.For example when i enter height : 13, width : 4 it writes one more,if witdh is 1 it enters infinite loop.While trying to solve it became too conflicted.Must i fix it or rewrite ? Here is the code : height =10, width = 5

```

|*____|    
|_*___|
|__*__|
|___*_|
|____*|
|___*_|
|__*__|
|_*___|
|*____|
|_*___|

```

```
      private static void Function()
      {
        int height, width;

        if (width == 2)
            while (height > 0)
            {
                FirstPart(width, height);
                height -= width;
            }
        else
            while (height > 0)
            {
                if (height > 1)
                {
                    FirstPart(width, height);
                    height -= width;
                }
                if (height > 0)
                {
                    SecondPart(width, height);
                    height -= width - 2;
                }
            }
    }

    private static void FirstPart(int width,int height)
    {

        if(height > width)
             for (int i = 0; i < width; i++)
             {
                for (int j = 0; j < width+2; j++)
                {

                    if (j == 0 || j == width + 1)
                        Console.Write("|");
                    else
                         if (i + 1 == j)
                            Console.Write("*");
                         else
                             Console.Write(" ");
                }
             Console.WriteLine();
        }
        else
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width + 2; j++)
                {

                    if (j == 0 || j == width + 1)
                        Console.Write("|");
                    else
                        if (i + 1 == j)
                            Console.Write("*");
                        else
                            Console.Write(" ");
                }
                Console.WriteLine();
            }
    }
    private static void SecondPart(int width,int height)
    {

        if(height > width)

            for (int i = 0; i < width-2; i++)
            {
               for (int j = 0; j < width+2; j++)
               {

                if (j == 0 || j == width + 1)
                    Console.Write("|");
                else
                    if (i + j == width-1)
                        Console.Write("*");
                    else
                        Console.Write(" ");
            }
            Console.WriteLine();
        }
        else
            for (int i = 0; i < height; i++)
            {                                     
                for (int j = 0; j < width + 2; j++)
                {
                    if (j == 0 || j == width + 1)
                        Console.Write("|");
                    else
                        if (i + j == width - 1)
                            Console.Write("*");
                        else
                            Console.Write(" ");
                }
                Console.WriteLine();
            }
    }            

```
['https://Stackoverflow.com/questions/6763429', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/852118/']
```
    private static void WriteStars(int width, int height)
    {
        int j = 0;
        for (int i = 0; i < height; i++)
        {
            Console.Write("|");
            for (int f = 0; f < width; f++)
            {
                if (f == Math.Abs(j))
                {
                    Console.Write("*");
                }
                else
                {
                    Console.Write(" ");
                }
            }
            j++;
            if (Math.Abs(j) == width - 1)
            {
                j *= -1;
            }
            Console.WriteLine("|");
        }
    }

```

Probably going to get downvoted for giving you a complete answer, but maybe it'll show you one correct approach and you can learn something from it...
even shorter:

```
static void Variante_2(int height, int width)
{
  byte[][] arr = new byte[height][];
  int pos = 0;
  int mov = 1;
  for (int line = 0; line < height; line++)
  {
    arr[line] = new byte[width];
    for (int col = 0; col < width; col++) { arr[line][col] = 45; }
    arr[line][pos] = 42;
    pos += mov;
    if (pos == 0 || pos == (width - 1)) { mov *= -1; }
    Console.WriteLine("|" + ASCIIEncoding.ASCII.GetString(arr[line]) + "|");
  }
  string temp = Console.ReadLine();
}

```