Back to course

Understanding Loops: While and Do-While

.NET Zero to Hero: Master C# and Modern App Development

Loops: Repeating Tasks

While Loop:

Runs as long as a condition is true. csharp int i = 0; while (i < 5) { Console.WriteLine(i); i++; }

Do-While Loop:

Always runs at least once, then checks the condition. csharp do { Console.WriteLine("I run once regardless"); } while (false);