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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...