ideas | discover | explore

Thursday, September 29, 2011

C# 8 - For loop statement

1. Create a new console project.
2. Edit the Program.cs inside static void Main(string[] args) file as shown below.
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Hello World!");
            }
            
            Console.WriteLine("Press any key to continue.....");
            Console.ReadLine();
        }

3. Press F5 to run and see the results.



4. Thank you.


The for-loop statement is used perform a piece of code multiple times as long as the condition set is evaluated to true. Its syntax is:

for(<initialization>;<condition>;<incrementation/decrementation>)
{
                //code to execute
}

No comments: