Goto statement In C#
The goto is C# unconditional jump statement. When encountered, program flow jumps to the location specified by the goto.
The goto requires a label of operation. A label is a valid C# identifier followed by colon.
There are different-different ways for using Goto statement such as:
int x = 1;
Loop:
x++;
if (x < 100)
{
goto loop;
}
Here is the example
string Fruit = "Apple";
switch (Fruit)
case "Banana":
MessageBox.Show(Fruit + " is the delecious fruit");
break;
case "Chair":
case "Apple":
goto case "Banana";
case "Table":
goto case "Chair";
default:
MessageBox.Show("Select valid option");
In this case, case and default statements of a Switch are labels thus they can be targets of a goto. However, the goto statement must be executed from within the switch. that is we cannot use the goto to jump into switch statement .
int a = 0;
while (a < 10)
if (a == 5)
goto cleanup;
cleanup: MessageBox.Show(a);
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: