The break statement is used to terminating the current flow of program and transfer controls to the next execution.
Example:
Output
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....
Example:
using System;
namespace break_statement
{
class Program
{
static void Main(string[] args)
{
int i = 0;
while (i < 100)
{
Console.WriteLine(i);
if (i == 20)
{
Console.WriteLine("breaking the current segment...");
break;
}
i++;
}
Console.ReadLine();
}
}
}
namespace break_statement
{
class Program
{
static void Main(string[] args)
{
int i = 0;
while (i < 100)
{
Console.WriteLine(i);
if (i == 20)
{
Console.WriteLine("breaking the current segment...");
break;
}
i++;
}
Console.ReadLine();
}
}
}
Output
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....
Comments
Post a Comment