Introduction
In this blog post, we are going to focus on the jump statements of the C# language. You’ve probably been working with it for a while, but needed more clarity, especially with the notorious goto statement. Thus, that’s the main goal of this post. However; If you are a total beginner, I encourage you to continue reading until the end without skipping.
C# provides three (3) different types of jump statements that enable you to move immediately to another line in the program. These jump statements are break, continue and goto. Thus, these jump statements are very handy in one of these scenarios: in case that you need to terminate a loop before it has reached the end or might need to skip an iteration of a loop.
Break statement
Let me guess, you’ve met the break statement for the first time when you used it to exit inside a switch statement.
See the example below:
- [Flags]
- public enum Status : byte
- {
- NotStarted = 0,
- InProgress = 1,
- Done = 2
- }
- Status myStatus = Status.Done;
- switch (myStatus)
- {
- case Status.NotStarted:
- //do something
- break;
- case Status.InProgress:
- //do something
- break;
- case Status.Done:
- //do something
- break;
- default:
- break;
- }
As you learn more about the C# language, you’ve possibly faced with the different looping statements such as for, for-each, while, and do-while loops. In fact, break can be also used to exit from these looping statements.
See the example below:
- [Fact]
- public void Jump_Statement_Break_Test()
- {
- int counter = 0;
- int length = 10;
- int breakWhenEqualsToFive = 5;
- string message = string.Empty;
- for (int i = 0; i < length; i++)
- {
- counter = i;
- message += $"Inside the loop counter = {counter} to {length}.{Environment.NewLine}";
- if (i == breakWhenEqualsToFive)
- {
- message += $"Breaking out counter at counter = {counter}";
- break;
- }
- }
- Assert.Equal(breakWhenEqualsToFive, counter);
- this._output.WriteLine(message);
- }
See the sample output below:

Continue statement
You might be asking: “So, is the continue statement similar to the break statement?”. You are correct, but there is a slight difference. The continue statement causes the program control to jump back to skip and start the loop rather than restarting outside the loop altogether.
See the example below:

preeti kumariPosted Feb 5, 2020, 4:19 AM
Very well explained.