CSharp examples for Language Basics:goto
The goto statement transfers execution to another label within a statement block.
The form is as follows:
goto statement-label;
Or, when used within a switch statement:
goto case case-constant;
A label is a placeholder in a code block that precedes a statement, denoted with a colon suffix.
The following iterates the numbers 1 through 5, mimicking a for loop:
using System;/* w w w. ja v a 2s . c o m*/ class Test { static void Main(){ int i = 1; startLoop: if (i <= 5) { Console.Write (i + " "); i++; goto startLoop; } } }