Sunday, December 28, 2014

Program to show the use of break statement and continue statement

9:00 PM - By azeheruddin khan 0

Description: - ‘break’ statement is used to exit or come out of a loop or switch case without checking the condition of a loop. Execution of ‘continue’ statement makes flow of execution to repeatedly go back to the condition of the loop without executing instructions after it, until an if condition before the “continue” statement becomes false.

Example:

using System;

namespace ArithmeticExample
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            Console.WriteLine("BREAK STATEMENT");
            while (i <= 100)
            {
                Console.Write(i + " ");
                i++;
                if (i > 20)
                {
                    break;
                }
            }

            i = 1;
            Console.WriteLine();
            Console.WriteLine("CONTINUE STATEMENT");
            for (i = 1; i <= 20; i++)
            {
                if (i % 2 == 0)
                {
                    continue;
                }
                else Console.Write(i + " ");
            }
            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