Print a console square in C#

Print a console square in C#

SharpestC

So I also started a C# (C sharp) course. The first task utilized the stuff I'd learned on my C - course

The first task was to print a simple square with nothing in the middle using C#.

This ended up being quite fun and I was able to implement stuff I'd learned previously! The print happened with a simple 2 x for-loop with i controlling the height of the square and j controlling the width. The output of the code was

sharp1

This was done to requirements. So it's a 10 x 4 square.

The code was

using System;


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
          
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (i == 0 || i == 3 || j == 0 || j == 9)
                    {
                        Console.Write('*');

                    }
                    else
                    {
                        Console.Write(' ');
                    }

                }

                Console.WriteLine();
            }

          
        }
    }
}

 

All in all a fun little exercise.