Use for loop as a while loop in CSharp

Description

The following code shows how to use for loop as a while loop.

Example


using System; //from www .j a va 2 s .c  om
 
public class MainClass {     
  public static void Main() { 
    int i; 
 
    i = 0; // move initialization out of loop 
    for(; i < 10; ) { 
      Console.WriteLine("Pass #" + i); 
      i++; // increment loop control var 
    } 
  }   
}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




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