C # break statement
C # in thebreak statement has the following two ways:
When abreak statement occurs within a loop, the loop will be immediately terminated and the program flow will continue to implement immediately the next statement cycle.
It can be used to terminatethe switch statement in a case.
If you are using a nested loop (ie a loop nested inside another loop), break statement to stop the execution of the innermost loop, and then start the next line of code after the block.
grammar
Thebreak statement syntax C #:
break;
flow chart
Examples
using System; namespace Loops { class Program { static void Main (string [] args) { / * Local variable definitions * / int a = 10; / * While loop is executed * / while (a <20) { Console.WriteLine ( "a value: {0}", a); a ++; if (a> 15) { / * Use the break statement to terminate the loop * / break; } } Console.ReadLine (); } } }
When the above code is compiled and executed, it produces the following results:
a value of: 10 a value of: 11 a value of: 12 a value of: 13 a value of: 14 a value of: 15