Friday, August 13, 2010

For Loop Demo C#


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

namespace Csharp
{
    class forloop
    {
        public static void Main(string[] args)
        {
            implement obj = new implement();
            obj.forloop();
            Console.ReadLine();
        }
    }
    class implement
    {

        public void forloop()
        {
            Console.WriteLine("The Output is displayed by using Console.WriteLine()\n");
               for(int i=0; i<5; i++)
               {
                   Console.WriteLine("{0}", i);
               }

            Console.WriteLine("\nThe Output is displayed by using Console.Write()\n");
               for (int i = 0; i < 5; i++)
               {
                   Console.Write("{0}\t", i);
               }
        }

    }
}

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

namespace Csharp
{
    /// <summary>
   
    /// </summary>
    class Extendingforloop
    {
        public static void Main(string[] args)
        {
            design obj = new design();
            obj.loop1();
            obj.loop2();
            obj.loop3();
            obj.loop4();
            //obj.loop5();
            Console.ReadLine();
        }
    }
    class design
    {
        public void loop1()
        {
            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0}",i);
                }
                Console.Write("\n");
            }
            Console.Write("\n");
        }
        public void loop2()
        {
            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0}", j);
                }
                Console.Write("\n");
            }
            Console.Write("\n");
        }
        public void loop3()
        {
            for (int i = 5; i >= 1 ; i--)
            {
                for (int j= 5;j >= i;j--)
                {
                    Console.Write("{0}", j);
                    if (i <1)
                        break;
                }
                Console.Write("\n");
            }
            Console.Write("\n");
        }
        public void loop4()
        {
            int i=6, c = 0;
            for (; i >= 0; i--)
            {
                c = i;
                Console.Write("\n");
                for (; ; )
                {
                    Console.Write("{0}", c);
                    if (c == 0)
                        break;
                    c--;

                }
            }

        }

No comments:

Post a Comment