Friday, March 10, 2017

Loop (do while loop)

// # The do ... while loop ensures that the body of the loop executes at least once.

// 1 to 100 series using do while
using System;

namespace TestLoop
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            do
            {
                Console.WriteLine("{0}\n", i);
                i++;
            }
            while (i <= 100);
            Console.ReadKey();
        }
    }
}
 

Loop (while loop)

//  #While loops are good for when the loop's terminating condition happens at some yet-to-be determined time.

// 1 to 100 series using while loop
using System;

namespace TestLoop
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            while (i <= 100)
            {
                Console.WriteLine("{0}\n",i);
                i++;
            }
            Console.ReadKey();
        }
    }
}

Loop (for loop)

// # If you know the number of iterations the loop should run beforehand, then we use for loop

// 1 to 100 series using for loop
using System;

namespace LoopTest
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 100; i++)
            {
                Console.WriteLine("{0}\n", i);
            }
            Console.ReadKey();
        }
    }
}

Sunday, March 5, 2017

Condition (if else) Statement

using System;
namespace ConditionApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int firstNumber, secondNumber;

            Console.Write("Enter First Number :");
            firstNumber = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter Second Number:");
            secondNumber = Convert.ToInt32(Console.ReadLine());

            if(firstNumber==secondNumber)
            {
                Console.WriteLine("{0} is Equel {1}", firstNumber, secondNumber);
            }
            else if (firstNumber > secondNumber)
            {
                Console.WriteLine("{0} is Bigger then {1}", firstNumber, secondNumber);
            }
            else
            {
                Console.WriteLine("{0} is Less then {1}", firstNumber, secondNumber);
            }

            Console.ReadKey();
        }
    }
}

ASP.NET VS PHP VS JSP