The for loop is used when you know in advance how many times you want to repeat a block of code.
for
Syntax:
for (initialization; condition; increment)
{
// Code to execute
}
Example:
for (int i = 0; i < 5; i++)
Console.WriteLine("Value of i: " + i);
Explanation:
int i = 0 → Start at 0
int i = 0
i < 5 → Continue looping while i is less than 5
i < 5
i
i++ → Increase i by 1 each time
i++