navigation
c# .net

how to use for loop in C#?

| | CSharp

For loop that needs to execute a specific number of times until a specified expression evaluates to false.


Syntax for for loop:


 for ( init; condition; increment )
{
statement(s);
}


class exampleforloop
{
static void Main()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i);
}
}
}


Output:
1
2
3
4
5