C# Goto Statement

Prabhukiran345
Posted by Prabhukiran345 under C# category on | Points: 40 | Views : 503
Definition: The goto statement is a jump statement that controls the execution of the program to another segment of the same program. You create label at anywhere in program then can pass the execution control via the goto statements.
using System;

namespace goto_statement
{
class Program
{
static void Main(string[] args)
{
string name;

label: //creating label with colon(:)

Console.WriteLine("Enter your name:");
name = Console.ReadLine();

Console.WriteLine("Welcome {0}", name);

goto label; //jump to label statement
}
}
}

OUTPUT:
Enter your name :
Prabhu
Welcome Prabhu
Enter your name :
Kiran
Welcome Kiran
Enter your name :
XYZ
Welcome XYZ
Enter your name :

Comments or Responses

Login to post response