CSharp examples for Language Basics:break
break statement exiting a for statement.
using System;/*from www . j a va2 s .co m*/ class BreakTest { static void Main() { int count; // control variable also used after loop terminates for (count = 1; count <= 10; ++count) // loop 10 times { if (count == 5) // if count is 5, { break; // terminate loop } Console.Write($"{count} "); } Console.WriteLine($"\nBroke out of loop at count = {count}"); } }