Sample program containing a break statement : Break « Language « C++






Sample program containing a break statement

Sample program containing a break statement
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
   int ac = 32;          
                         
   while(true)
   { 
     cout << "Character   Decimal   Hexadecimal\n\n";
     int upper;
     for( upper =ac + 20; ac < upper && ac < 256; ++ac)
        cout << "      " << (char)ac     
             << setw(10) << dec << ac
             << setw(10) << hex << ac << endl;
     if( upper >= 256)   
        break;
     cout <<"To Go on, hit <return>, to Stop hit <q>+<return>";
     char answer;
     cin.get(answer);
     if( answer == 'q' || answer == 'Q' )
       break;
     cin.sync();
   }
   return 0;
} 

           
       








Related examples in the same category

1.Use the break keyword to provide the user with the option of quitting the data entry