The for loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false. It takes the following form:
for ([initializers]; [expression]; [iterators]) statement
where:
The for statement executes the statement repeatedly as follows:
Because the test of expression takes place before the execution of the loop, a for statement executes zero or more times.
All of the expressions of the for statement are optional; for example, the following statement is used to write an infinite loop:
for (;;) {
...
}
// statements_for.cs
// for loop
using System;
public class ForLoopTest
{
public static void Main()
{
for (int i = 1; i <= 5; i++)
Console.WriteLine(i);
}
}
1 2 3 4 5
C# Keywords |