Studytonight is now part of the GUVI universe. Explore GUVI →
🤩 New Cool Developer Tools for you. Explore →
FREE JavaScript Video Series Start Learning →
Signup/Sign In
Tests
MCQs to test your knowledge.
Compilers
Compilers to execute code in browser.
Index
LAST UPDATED: NOVEMBER 1, 2020

C++ Break Statement in Loop Program

Hello Everyone!

In this tutorial, we will learn how to demonstrate the concept of break statement in loops, in the C++ programming language.

Code:

#include <iostream>
using namespace std;
int main()
{
 cout << "\n\nWelcome to Studytonight :-)\n\n\n";
 cout << " ===== Program to understand the break keyword ===== \n\n";
 // Local variable declaration and initialization:
 int n = 10;
 // do loop execution
 do
 {
 cout << "Value of variable n is : " << n << endl;
 n = n + 1;
 if (n == 15)
 {
 // terminate the loop and execute the next statement following it.
 cout << "\n\nExecuting the break statement and terminating the loop.\n\n";
 break;
 }
 } while (n < 20);
 cout << "The value at which the loop got terminated is : " << n << "\n\n\n";
 return 0;
}

Output:

C++ break in loops

We hope that this post helped you develop a better understanding of the concept of break statement in loops, in C++. For any query, feel free to reach out to us via the comments section down below.

Keep Learning : )



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.

Learn to Code
Learn and practice coding side-by-side.
NEW
C language Course
115+ coding exercises
Javascript Course
85+ coding exercises

AltStyle によって変換されたページ (->オリジナル) /