Using break to exit a loop
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Using break to exit a loop.
using System;
public class BreakDemo {
public static void Main() {
// use break to exit this loop
for(int i=-10; i <= 10; i++) {
if(i > 0) break; // terminate loop when i is positive
Console.Write(i + " ");
}
Console.WriteLine("Done");
}
}
Related examples in the same category