Break quits only the loop that is currently active. - C++ Statement

C++ examples for Statement:break

Introduction

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

Demo Code

#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;
}

Result


Related Tutorials