Sunday, December 28, 2014

Program to demonstrate for loop, while loop and do while loop

8:58 PM - By azeheruddin khan 0

Description: - There are three types of loop constructs:-

  1. While: - This loop construct is used to execute a block of statements repeatedly until a particular condition or expression becomes false. This loop construct is used to execute both definite and indefinite loops. 
  2. Do-While: - This loop construct is also used to execute a block of statements repeatedly until a particular condition or expression becomes false. But, here the block of statements are executed at least once before evaluating the condition or expression. This loop construct is used to execute both definite and indefinite loops.
  3. For: - This loop construct is also used to execute a block of statements repeatedly until a particular condition or expression becomes false. This loop construct is used to execute only definite loops.

Example:

using System;

namespace ArithmeticExample
{
    class Program
    {

        static void Main(string[] args)
        {
            int n;
            int i = 0;
            Console.WriteLine("enter the number:");
            n = Convert.ToInt16(Console.ReadLine());
            for (; i <= n; i++)
            {
                Console.WriteLine(n + "*" + i + "=" + n * i);
            }

            i = 0;
            Console.WriteLine("enter the number:");
            n = Convert.ToInt16(Console.ReadLine());
            while (i <= 10)
            {
                Console.WriteLine("{0} * {1} = {2}", n, i, n * i);
                i++;
            }

            i = 12;
            Console.WriteLine("enter the number:");
            n = Convert.ToInt16(Console.ReadLine());
            do
            {
                Console.WriteLine(n + "*" + i + "=" + n * i);
                i++;
            } while (i <= 11);

            Console.ReadLine();

        }
    }
}


Output:









About the Author

I am Azeheruddin Khan having more than 6 year experience in c#, Asp.net and ms sql.My work comprise of medium and enterprise level projects using asp.net and other Microsoft .net technologies. Please feel free to contact me for any queries via posting comments on my blog,i will try to reply as early as possible. Follow me @fresher2programmer
View all posts by admin →

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

adsense

© 2014 Fresher2Programmer. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top