C# tutorial- Loops-break and continue a loop

break and continue a loop


The break command can be used to exit a loop at any time. In the example code below, the for loop will exit when the value of i is equal to 5. The program will print "I like C# programming language." five times and then the loop will exit.


int i;
for (i = 1; i <= 10; i++)
   Console.WriteLine("I like C# programming language.");

   if(i==5) break;



The continue command lets the program start the next iteration of the loop. See the example code below. The while loop continues if i is smaller than or equal to 5.


int i=1;
while(i <= 5)
   Console.WriteLine("I like C# programming lanuage.");



Vipin Tyagi comment

 Vipin Tyagi

The continue loop not work in While condition.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.