How to use Break Statement In C# With Example
Syntax:jump-statement;
break;
C# Break Statement Example
Let's see a simple example of C# break statement which is used inside the loop.
using System;
public class BreakExample
{
public static void Main(string[] args)
{
for (int i = 1; i <= 10; i++)
{
if (i == 5)
{
break;
}
Console.WriteLine(i);
}
}
}
C# Break Statement with Inner Loop
using System;
public class BreakExample
{
public static void Main(string[] args)
{
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
if(i==2&&j==2){
break;
}
Console.WriteLine(i+" "+j);
}
}
}
}
Post a Comment