The break statement in C# has following two usage:
- When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.
- It can be used to terminate a case in the switch statement.
If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.
The syntax for a break statement in C# is as follows:
static void Main(string args)
int i = 0;
while (i < 100)
if (i == 20)
Console.WriteLine("breaking the current segment..."); break;
When the above code is compiled and executed, it produces the following result:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 breaking the current segment