Tracks
/
C#
C#
/
Syllabus
/
Do While Loops
Do

Do While Loops in C#

1 exercise

About Do While Loops

To repeatedly execute logic, one can use loops. If the code in a loop should always be executed at least once, a do/while loop can be used:

int x = 0;

do
{
    x = GetX();
    // do something with x
}
while (x != 0);

This is used less frequently than a while loop but in some cases results in more natural looking code.

Edit via GitHub The link opens in a new window or tab

Learn Do While Loops