Loops in C#
Introduction
In this lesson, you will learn loops in C# for beginners. Loops help you repeat a block of code multiple times without writing it again.
What are Loops?
Loops are used to execute code repeatedly based on a condition.
Types of Loops in C#
for Loop
Used when you know how many times to run the loop:
for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
while Loop
Runs while a condition is true:
int i = 0;
while (i < 5)
{
Console.WriteLine(i);
i++;
}
do-while Loop
Runs at least one time before checking condition:
int i = 0;
do
{
Console.WriteLine(i);
i++;
} while (i < 5);
Real-World Use
- Display lists of data
- Process multiple records
- Repeat tasks automatically
Key Points
- Loops reduce code repetition
- for loop is used for fixed iterations
- while loop is used for conditions
Internal Links
- Course Page: .NET Course for Beginners



