public class BreakTest
1: // Fig. 5.12: BreakTest.java
2: // break statement exiting a for statement.
3: public class BreakTest
4: {
5: public static void main( String args[] )
6: {
7: int count; // control variable also used after loop terminates
8:
9: for ( count = 1; count <= 10; count++ ) // loop 10 times
10: {
11: if ( count == 5 ) // if count is 5,
12: break; // terminate loop
13:
14: System.out.printf( "%d ", count );
15: } // end for
16:
17: System.out.printf( "\nBroke out of loop at count = %d\n", count );
18: } // end main
19: } // end class BreakTest
20:
21:
22: /**************************************************************************
23: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
24: * Pearson Education, Inc. All Rights Reserved. *
25: * *
26: * DISCLAIMER: The authors and publisher of this book have used their *
27: * best efforts in preparing the book. These efforts include the *
28: * development, research, and testing of the theories and programs *
29: * to determine their effectiveness. The authors and publisher make *
30: * no warranty of any kind, expressed or implied, with regard to these *
31: * programs or to the documentation contained in these books. The authors *
32: * and publisher shall not be liable in any event for incidental or *
33: * consequential damages in connection with, or arising out of, the *
34: * furnishing, performance, or use of these programs. *
35: *************************************************************************/