Back to course

While and Do-While Loops

C# Zero to Hero: Comprehensive Programming Masterclass

While and Do-While Loops

Loops used when the number of iterations is not known beforehand.

While Loop

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

Do-While Loop

Executes code once before checking the condition. csharp do { Console.WriteLine(i); i++; } while (i < 5);