C++ break statement Break quits only the loop that is currently active.

Introduction

break is usually placed inside a while or do-while loop to "simulate" a finished loop.

#include <iostream>
using namespace std;
int main()//from  w w w .j av  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;
}



PreviousNext

Related