C++ examples for Statement:break
break is usually placed inside a while or do-while loop to "simulate" a finished loop.
#include <iostream> using namespace std; int main()/* w w w . j a v a 2 s. c o m*/ { char user_ans; do { cout << "C++ is fun! \n"; break; // Causes early exit. cout << "Do you want to see the message again (N/Y)? "; cin >> user_ans; } while (user_ans == 'Y'); cout << "That's all for now\n"; return 0; }