c# nested if else

Here is an example of nested if else in C#

static void Main(string[] args)
        {
            string str;
            Console.WriteLine("Enter any value: ");
            str = Console.ReadLine();
            int a = int.Parse(str);

            if (a > 0 && a <= 20)
            {
                Console.WriteLine("between 0 and 20");
            }
            else if (a > 21 && a <= 40)
            {
                Console.WriteLine("between 21 and 40");
            }
            else if (a > 41 && a <= 60)
            {
                Console.WriteLine("between 41 and 60");
            }
            else if (a > 60)
            {
                Console.WriteLine("greater than 60");
            }
            Console.WriteLine("value = " + a);
        }

 

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *