Use a while loop to repeat a block of code as long as a condition is true.
Write a While Statement in C#
💻 C# Basic Syntax
while (<CONDITION>)
{
// statements to repeat
}
💻 C# Example
int energy = 5;
while (energy > 0)
{
Console.WriteLine("Player runs");
energy--; // decrease energy to eventually end the loop
}
Related Concepts
- Creates: While Statement