C# Error CS0139 – No enclosing loop out of which to break or continue

C# Compiler Error

CS0139 – No enclosing loop out of which to break or continue

Reason for the Error

You will receive this error when you use either break or continue outside of a loop in C#.

For example, the below code snippet shows the usage of the continue statement in C# directly with-in the Main function which results with the error CS0139.

namespace DeveloperPublishNamespace
{
    public class DeveloperPublish
    {
        public static void Main()
        {
            continue;
        }
    }

}
C# Error CS0139 – No enclosing loop out of which to break or continue

Error CS0139 No enclosing loop out of which to break or continue ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 7 Active

Solution

To fix the error code CS0139, ensure that you use continue and break statements with-in the loop or in places where it is allowed in C#.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...