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; } } }
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#.