Friday, December 12, 2008

For Statement:

Definition:

A for statement evaluates a sequence of initialization expressions and then, while a condition is true, repeatedly executes a statement and evaluates a sequence of iteration expressions.

In the below example will show you how to print numbers from 1 to 5

Example:

class Program
{
static void Main(string[] args)
{
int i = 1;
for (; i <= 5; i++) {
Console.WriteLine(i);
Console.ReadLine();
}
}
}


Output:
1
2
3
4
5

No comments: