For loop
Visit each number in order. Print it, move to the next number, and finish after the last value.
Simple example
Print the numbers from one to three.
Start1 → 3
Result1
2
3
using System;
for (int number = 1; number <= 3; number++) {
Console.WriteLine(number);
}
1 2 3
Advertisements
Everyday examples
Three friends stand in a ticket queue. Print the next three ticket numbers, starting at 41.
Start41 → 43
Result41
42
43
using System;
for (int ticket = 41; ticket <= 43; ticket++) {
Console.WriteLine(ticket);
}
41 42 43
Run the example
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson