Advertisement
Advertisement
//C# Break statement example
using System;
class BreakEx
{
public static void Main()
{
// A for loop to print the digits from 0 to 9
for(int i=0;i<10;i++)
{
//checking if the value in i is equal to 5
// If yes, the break statement is called.
if(i==5)
break; //when i is equal to 5, this break statement takes the control out of loop
//Printing the value of i
Console.WriteLine(i);
}
Console.WriteLine("Out of the loop");
}
}
0
1
2
3
4
Out of the loop
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement