Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 11:13, 15 August 2025 by Dylan (talk | contribs) (replace 'String' with 'string' in code example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A while loop will repeat (iterate) a code block while a condition is true.

This type of loop is known as indefinite iteration.

Example

The following C Sharp code will loop until the user enters 'stop':

string input;
while (input != "stop")
{
    input = Console.ReadLine();
}

Do while loop

If you want the code to run at least once before checking the condition, you can use a do while loop.

See: Do while loop