![]() |
In C++, the switch statement allows us to select a code block to be executed based on some conditions among many alternatives (listed in the form of cases). The break keyword plays an important role in the functioning of a switch statement. In this article, we will learn why breaks are used in C++ switch statements. Need of Break in C++ Switch StatementIn a switch statement, the break keyword is used as a control mechanism to stop the execution of code blocks once the required condition is met and the case is executed.
Each case block finishes with the break statement. Without it, the program will continue to execute all the subsequent cases until the end of the switch statement is reached this condition is called fallthrough behavior. Syntax of break in C++ Switch Statementswitch(expr) C++ Program to Demonstrate the Use of Break in Switch StatementThe below example demonstrates how we can use the break keyword in a switch statement in C++.
Output Good job! Time Complexity: O(1)
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 18 |