DEV Community

Tania
Tania

Posted on • Originally published at kodlogs.com

C++ what does break do

Contents
Break in C/C++
Switch statement
Syntax
Flow Diagram
C++ Break
Summary
Article Tags
Example

Break Statement in C/C++:
This is often the case in real life. We have to choose one of many items. For example, choose one of many programming languages. Choose one of the many programming websites. Choosing a hotel to dine at. Choosing one of the many institutes. In such a situation the use of if statement becomes very long and complicated. C ++ alternative control statement to solve this problem. With the help of this you can transfer control to any part of the program. So dear student, before clarifying the break statement, I will tell you to use the switch statement first so that you can use the break statement properly. This is the control statement that allows us to select one of the many cases and follow the statement written under that case.

Switch statement :

If the switch statement is viewed more comprehensively, then it is switch case. Default. Because these three specific words combine to form a control statement. Any integer expression can be given in brackets after the specific word of ch. which gives a number. When that number is like the number in front of a case, then the program along with all the statements written under that case. Also executes all the given case and default statement given later. So now if we talk about break statement then let's try to understand.

Syntax :
The syntax of a break statement in C++ is −

Break;
Flow Diagram:

C++ Break:
If you want only case 2 to be executed. It is important that the control of the program be transferred from the switch statement to the next line of the program as soon as the case statement is executed. For this, the specific word break of C should be added at the end of each case statement. By doing so, our goal will be achieved. I hope you have understood the break statement well.
It was used to "jump out" of a switch statement.The break statement can also be used to jump out of a loop.

Summary :

Today we understand kodlog website, I try to explain the break statement . I hope after reading this article you will be able to understand the break statement . I would like to have feedback from my kodlog site. Please post your feedback, question, or comments about this article.

Article Tags :
C#|Python |Python 3|pycharm | html | java |JavaScript |cpp|code|rubi|Network | Google |html5 |php|bootstrap |string |Microsoft |variable |syntax |Coders |Codinglove|
Computerscience|wordpress|html-page|php|
Xml|game| net| list | loop | integer |float | string | double |

Example:

#include <iostream>
using namespace std;

int main() {
    int i = 0;

    while (i < 10) {
        if (i == 5) {
            break;
        }
        cout << i << '\n';
        i++;
    }

    i = 0;
    do {
        if (i == 5) {
            break;
        }
        cout << i << '\n';
        i++;
    } while (i < 10);
}
Enter fullscreen mode Exit fullscreen mode

OUTPUT

In each case 
01234
Enter fullscreen mode Exit fullscreen mode

Top comments (0)