goto Statements

The goto statement allows unconditional branching to another program section. The form of the goto statement is as follows:

goto label;

The destination is marked by a label. Legal destinations include the current level of the goto statement or outside of the current loop.

For C++ Programmers

C++ goto statements can transfer control to anywhere in a program. C# goto statements must always jump at the same level or higher out of its enclosing block.

For Java Programmers

Java does not have a goto statement. In C#, the goto statement has restrictions that make it similar to a Java labeled break statement.

The following code shows how a goto statement could be used.

 do { // some processing while (/* some Boolean condition */) ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.