Create a for loop without increase in CSharp

Description

The following code shows how to create a for loop without increase.

Example


 using System;/*from  w w  w . j av a2 s .  c  o m*/
 public class MainClass{
     public static void Main()
     {

         for (int counter = 0; counter<10; ) // no increment
         {
             Console.WriteLine(
                 "counter: {0} ", counter);

             // do more work here

             counter++; // increment counter
         }
     }
 }

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




C# Hello World
C# Operators
C# Statements
C# Exception