C# if statement and goto statement example


using System;

namespace ClassRoomSamples
{
    class Demo03conditionalStatement
    {
        static void Main(String[] anyname)
        {
            Console.WriteLine("Enter Name");
            string EmpName = Console.ReadLine();

            //It is label you can any name here, should end with colon
            ReadMarks: 
            Console.WriteLine("Enter Score (Max 10)");
            Int32 score = int.Parse(Console.ReadLine());

            if (score > 10)
            {
                Console.WriteLine("Score should be less then 10");
                goto ReadMarks;
            }
            //selection
            if (score >= 7)
            {
                Console.WriteLine($"Hello {EmpName},Your are selected");
            }
            else
            {
                Console.WriteLine($"Hello {EmpName} You are not                                                                        Selected");
            }
            Console.ReadKey();
        }
    }
}


No comments:

Post a Comment