As other answers have said, just use the break statement to exit your loop. Consider the following code
public void TestMethod()
{
for (int i = 0; i < 1000; ++i)
{
if (i == 10)
break;
}
}
In this code, we've set a loop to iterate 1000 times.
However, the if statement is checking for when i == 10, when this happens the
break
statement will be hit and the loop will exit.
Because there is no other code after this, the method will exit as soon as we exit the loop.