Back to course

The For Loop and Nested Loops

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

Master the For Loop

The for loop is most common when you know exactly how many times you want to iterate.

Syntax:

csharp for (int i = 0; i < 10; i++) { Console.WriteLine($"Iteration {i}"); }

Nested Loops:

A loop inside another loop. Common for processing grids or tables: csharp for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { Console.Write($"({i},{j}) "); } Console.WriteLine(); }