More actions
Updated via bot |
(No difference)
|
Latest revision as of 16:05, 21 October 2025
Stop a while loop before it naturally finishes using a break statement.
Break a While Loop in C#
💻 C#
bool playerIsAlive = true;
while (playerIsAlive)
{
if(playerQuitsGame)
{
break; // Break early from the loop.
}
// Run game logic.
}
// Exit the game.
Related Concepts
- Uses: Break Statement
- Uses: While Statement