Iteration or repetition is the term used to refer to control statements that allow blocks of code to be repeated. The For loop allows the programmer to repeat code a specific number of times.
Study the following code carefully. A for loop always has a stepper variable. This variable holds a different value on each iteration. The loop below counts from 1 to 10 inclusive.
for (int count = 1; count <= 10; count++)
{
Console.WriteLine("{0}.", count);
}
Console.ReadLine();
If you want your program to miss out the loop on specific iterations, you can use the continue statement. It moves to the end of the current iteration and begins the next if there is one. This program only displays the odd numbers.
for (int count = 1; count <= 10; count++)
{
if (count % 2 == 0)
{
continue;
}
Console.WriteLine("{0}.", count);
}
Console.ReadLine();
You can use the break statement within a loop to force the loop to end prematurely if some condition or other is met.