for and foreach Loop Example

for and foreach Loop Example.zip

//Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace forLoop.Example
{
    public class Program
    {
        public static void Main()
        {
            LoopDEMO fLD = new LoopDEMO();
            Console.ReadLine();
        }
    }
}

// LoopDEMO.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace forLoop.Example
{
    class LoopDEMO
    {
        public LoopDEMO()
        {
            Console.WriteLine("============  for Loop Example ============");
            int i = 0;
            for (i = 1; i <= 12; i = i + 1)
            {
                Console.WriteLine(" i = " + (i));
            }
            Console.WriteLine("============  foreach Loop Example ============");
            int[] values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            foreach (double elementValue in values)
            {
                Console.WriteLine(" i = " + "{0}", elementValue);
            }
        }
    }
}