C# - Difference between Continue & Break Statement

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		for(int i = 1; i < 6; i++)
		{
			//continue is like a special break statement in which instead of jumping off loop block, the current loop iteration(n) is treated as completed.
			//The execution is then forced to start with the next iteration(n+1) loop.
			if(i == 4)		
				continue;
			Console.WriteLine(i);
		}
		
		Console.WriteLine("Loop A is Completed");
		Console.WriteLine();
		
		for(int i = 1; i < 6; i++)
		{
			//The break statement will make the execution jumping off loop block. No more iteration(n+1) loop will be respected. 
			if(i == 4)		
				break;
			
			Console.WriteLine(i);
		}		
		Console.WriteLine("Loop B is Completed");
	}
}
;