Breaking Out of or Continuing a while Statement - CSharp Language Basics

CSharp examples for Language Basics:while

Description

Breaking Out of or Continuing a while Statement

Demo Code

class even//from www. j  av  a2s.  c  o  m
{
   public static void Main()
   {
      int ctr = 0;
      while (true)
      {
         ctr++;
         if (ctr > 10 )
         {
            break;
         }
         else if ( (ctr % 2) == 1 )
         {
            continue;
         }
         else
         {
            System.Console.WriteLine("...{0}...", ctr);
         }
      }
      System.Console.WriteLine("Done!");
   }
}

Result


Related Tutorials