Use break to exit a do-while loop in CSharp

Description

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

Example


/*  ww w  .  ja  v  a 2 s. c  o  m*/
using System; 
 
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