C# Goto Statement

The goto statement is a jump statement that controls the execution of the program to a different section of an equivalent program. You produce label at anywhere in program then will pass the execution management via the goto statements.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GoTo_Statements_Example
 class Program
 static void Main(string[] args)
 string stringName;
 label: //creating label with colon(:)
 Console.WriteLine("Enter your name: ");
 stringName = Console.ReadLine();
 Console.WriteLine("Welcome {0}", stringName);
 Console.WriteLine("Press Ctrl + C for Exit\n");
 goto label; //jump to label statement 

Leave a Reply

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