You can repeatedly execute a sequence of code by creating a loop.
The general form of the for loop for repeating a single statement is
for(initialization; condition; iteration)
statement;
For repeating a block, the general form is
for(initialization; condition; iteration)
{
statement sequence
}
using System;
class MainClass {
public static void Main() {
int count;
for(count = 0; count < 5; count = count+1)
Console.WriteLine("This is count: " + count);
Console.WriteLine("Done!");
}
}
This is count: 0
This is count: 1
This is count: 2
This is count: 3
This is count: 4
Done!