Use any bool expression to control for loop in CSharp

Description

The following code shows how to use any bool expression to control for loop.

Example


using System; //  w  w  w  .  j a  v  a 2s. c  o  m
 
public class MainClass {    
  public static void Main() {    
    int i, j; 
    bool done = false; 
 
    for(i=0, j=100; !done; i++, j--) { 
 
      if(i*i >= j) done = true; 
 
      Console.WriteLine("i, j: " + i + " " + j); 
    } 
 
  }    
}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




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