break
Go Up to Keywords, Alphabetical Listing Index
Category
Syntax
Description
Use the break statement within loops to pass control to the first statement following the innermost switch, for, while, or do block.
Example
This example illustrates the use of keywords break, case, default, return, and switch.
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
char ch;
cout << "DRÜCKEN SIE a, b, ODER c. JEDE ANDERE AUSWAHL BEENDET DIESES PROGRAMM." << endl;
for ( /* IMMER */; cin >> ch; )
switch (ch)
{
case 'a' : /* DIE AUSWAHL VON a HAT EINEN EIGENEN ABLAUF. */
cout << endl << "Option a wurde gewählt." << endl;
break;
case 'b' : /* b UND c ERHALTEN GLEICHE ERGEBNISSE. */
case 'c' :
cout << endl << "Option b oder c wurden gewählt." << endl;
break;
default:
cout << endl << "KEINE GÜLTIGE AUSWAHL! Tschüß ..." << endl;
return(-1);
}
}