c# exit loop code example
Example 1: c# exit for
Use "break;"
for (int i = 1; i <= 100; i++)
{
if (i == 5)
{
break;
}
}
Example 2: c# stop loop
while (playerIsAlive)
{
// this code will keep running
if (playerIsAlive == false)
{
// eventually if this stopping condition is true,
// it will break out of the while loop
break;
}
}
// rest of the program will continue