Using break to exit a do-while loop in CSharp

Description

The following code shows how to using break to exit a do-while loop.

Example


using System; // w  w  w .ja va  2  s . c  o m
 
public class MainClass {  
  public static void Main() {  
    int i; 
 
    i = -10;     
    do { 
      if(i > 0) break; 
      Console.Write(i + " "); 
      i++; 
    } while(i <= 10); 
  
    Console.WriteLine("Done");  
  }  
}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




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