break; c# code example
Example 1: 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
Example 2: C# continue
class ContinueTest
{
static void Main()
{
for (int i = 1; i <= 10; i++)
{
if (i < 9)
{
continue;
}
Console.WriteLine(i);
}
// Keep the console open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
/*
Output:
9
10
*/