// // Filename: pgm2_8a.cpp // // Description: Demonstration of the break statement! // // ENSC 104: Digital Computer Programming // // Instructor: Dr. Walsh // // Section: 2 // // Date Created: 02/23/98 // Last Modified: 02/23/98 // // Name: N/A // #include main() { int x; for ( x = 1; x <= 10; x++) { if (x == 5) break; // break loop only if x == 5 cout << x << " "; } cout << endl << "Broke out of 'for' loop at x == " << x << endl << endl; x = 1; while( x <= 10 ) { if ( x == 5 ) break; // break loop only if x == 5 cout << x << " "; x++; } cout << endl << "Broke out of 'while' loop at x == " << x << endl << endl; x = 1; do { if ( x == 5 ) break; // break loop only if x == 5 cout << x << " "; x++; } while ( x <= 10 ); cout << endl << "Broke out of 'do while' loop at x == " << x << endl << endl; return 0; }