Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Write a While Statement

From Groundhog Learning

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