// // Filename: pgm2_7a.cpp // // Description: Demonstrating the 'do while' construct. // // ENSC 104: Digital Computer Programming // // Instructor: Dr. Walsh // // Section: 2 // // Date Created: 02/19/98 // Last Modified: 02/19/98 // // Name: N/A // #define COUNT 5 #include main() { int counter = 1; cout << "\n'do while' loop with pre-increment\n"; do { cout << counter << " "; } while ( ++counter < COUNT ); cout << endl; cout << "\n'do while' loop with post-increment\n"; counter = 1; do { cout << counter << " "; } while ( counter++ < COUNT ); cout << endl; cout << "\n'do while' loop with pre-decrement\n"; counter = COUNT; do { cout << counter << " "; } while ( --counter > 0 ); cout << endl; cout << "\n'do while' loop with post-decrement\n"; counter = COUNT; do { cout << counter << " "; } while ( counter-- > 0 ); cout << endl; cout << "\n'do while' loop with '+=' operator\n"; counter = 0; do { cout << counter << " "; } while ( (counter+=2) <= 10 ); // Better evaluate '+=' before '<' or else! cout << endl; return 0; }