| title | goto (C# Reference) | ||
|---|---|---|---|
| ms.date | 07/20/2015 | ||
| ms.prod | .net | ||
| ms.technology |
|
||
| ms.topic | article | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| ms.assetid | 2c03c9c1-8119-44ef-b740-fb3d287a42fe | ||
| caps.latest.revision | 22 | ||
| author | BillWagner | ||
| ms.author | wiwagn |
The goto statement transfers the program control directly to a labeled statement.
A common use of goto is to transfer control to a specific switch-case label or the default label in a switch statement.
The goto statement is also useful to get out of deeply nested loops.
The following example demonstrates using goto in a switch statement.
[!code-csharpcsrefKeywordsJump#4]
The following example demonstrates using goto to break out from nested loops.
[!code-csharpcsrefKeywordsJump#5]
[!INCLUDECSharplangspec]
C# Reference
C# Programming Guide
C# Keywords
goto Statement
Jump Statements