Saturday 25 January 2014

Continue Statement in C#

The continue statement in C# works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.
For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control passes to the conditional tests.

Syntax:

The syntax for a continue statement in C# is as follows:
continue;

Flow Diagram:

C# continue statement

Example:

using System;
 
namespace Continue_Statement
{
  class Program
   {
     static void Main(string[] args)
      {
        int i = 0; 
        while(i<10)
         {
           i++;
           if (i < 6)
            {
              continue;
            }    
           Console.WriteLine(i);
         }           
        Console.Read();
      }
   }
}
When the above code is compiled and executed, it produces the following result:
O/P :6 7 8 9 10
 

No comments:

Post a Comment

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...