C++ examples for Statement:break
Jump out of the loop and start executing the statements after the loop using the break
#include <iostream> using namespace std ; int main(){//from ww w . ja va2 s.co m cout << " Enter positive numbers followed "; cout << "by a negative number to quit \n"; int total = 0; while (true ) { int next ; cin >> next ; if (next <0) { break ; } total += next ; } cout << " The total is " << total << "\n"; }