Monday, March 17, 2014

Loop Structures (While)_Ex_1_Wk (5)_Feb 3

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

namespace IterationLoopStructure
{
    class Program
    {
        static void Main(string[] args)
        {
            //Write a while loop that repeat 10 times
            //1. Need a counter and initialize it

            int counter = 1;
            int sum = 0;
            while (counter <= 10)
            {
                sum += counter;
                Console.WriteLine("Counter: {0} Sum: {1}", counter, sum);
                counter++;
            }
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment