Introduction:

In this article we will explain how to use goto statement or what is goto statement in c# or how to transfer to execution the other section of the program with example.

Description:

The C# goto statement is a jump statement that controls the execution of the program. It is used to transfer to execution the other section of the program. It is directly jumps to the specified label.


  • C# Goto Statement Example

Let's see the simple example of goto statement in C#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Example
{
    class Program
    {
        public static void Main(string[] args)
        {
        acceptable:
            Console.WriteLine("You are not acceptable to admission!");
 
            Console.WriteLine("Enter your marks:\n");
            int marks = Convert.ToInt32(Console.ReadLine());
            if (marks < 50)
            {
                goto acceptable;
            }
            else
            {
                Console.WriteLine("You are acceptable to admission!");
            }
        }      }
}
 


OutPut:

You are not acceptable to admission!

Enter your marks:

30

You are not acceptable to admission!

Enter your marks:

45

You are not acceptable to admission!

Enter your marks:

50

You are acceptable to admission!



i hope It will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like