C# Jump Statements

The C# language provides three types of Jump Statements:
1. break
2. continue
3. goto

break:

An early exit from a loop can be accomplished by using break statement. These statements can also be used within while, do or for loops for en early exit. When the break statement is encountered inside a loop, the is immediately exited and the program continues with the statement immediately following the loop. It has the following syntax:

break;

Example:

while(test condition)
{
........
........
if(condition)
break;
......
......
}

continue:

The continue statement simply tells the compiler that “Skip the following statements and continue with the next iteration“. It has the following syntax:

continue;

goto:

If we want to jump a set of nested loops or to continue a loop that is outside the current one, we may have to use the goto statement. C# has retained the infamous goto and it also permits us to use labels. A label is any valid C# variable name ending with a colon. We can use labels anywhere in a program and it uses the goto statement to transfer the control to the statement marked by the label.

Example :

if(args.Length==0)
goto end;
Console.WriteLine(args.Length);
end; // label name
Console.WriteLine("end");
}