Continue in while : While « Language Basics « C# / C Sharp






Continue in while

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 */
using System;

namespace Client.Chapter_4___Program_Control
{
  public class MyMainClass11
  {
    static void Main(string[] args)
    {
      WhileContinue();
      WhileBreak();
      WhileGoto();
    }
    static void WhileContinue()
    {
      int a = 0;
      
      while(a < 10)
      {
        a++;
        if (a == 5)
        {
          a++;
          continue;
        }
      }

    }
    static void WhileBreak()
    {
      int a = 0;

      while (a < 10)
      {
        a++;
        if (a == 5)
          break;
      }

      a++;
    }
    static void WhileGoto()
    {
      int a = 0;

      while (a < 10)
      {
        if (a == 5)
          goto cleanup;
      }
    cleanup :

      Console.WriteLine(a);
    }
  }
}

           
       








Related examples in the same category

1.Compute the order of magnitude of an integer Compute the order of magnitude of an integer
2.Compute integer powers of 2Compute integer powers of 2
3.Display the digits of an integer in reverse orderDisplay the digits of an integer in reverse order
4.Using break to exit a do-while loopUsing break to exit a do-while loop
5.While TesterWhile Tester
6.Do While TesterDo While Tester
7.While SignalWhile Signal
8.While loop to display 1 to 5While loop to display 1 to 5
9.while loop to calculate and display the Fibonacci numbers less than 50while loop to calculate and display the Fibonacci numbers less than 50
10.a do...while loopa do...while loop
11.While true testWhile true test
12.Simplest do whileSimplest do while
13.Simplest while