How to: Break Out of an Iterative Statement
This example uses the break statement to break out of a for loop when an integer counter reaches 10.
Example
for (int counter = 1; counter <= 1000; counter+)
{
if (counter == 10)
break;
System.Console.WriteLine(counter);
}
Compiling the Code
Copy the code and paste it into the Main method of a console application.