Example of Using Range in C++ Switch Case
Below is the implementation of the above topic:
C++
// C++ Program to implement // Using Range in Swtich Case #include<iostream> using namespace std; // main function int main() { int a=8; // Switch Case switch (a) { // Range added to Switch case case 4 ... 10: cout<< "a is range 4 to 10" <<endl; break ; } } |
Output :
a is range 4 to 10
Note:
- We have to exactly use 3 dots other wise it will give us error while compilation.
- If low>high then also we will get an error
Using Range in C++ Switch Case
In C++, we generally know about the switch case which means we give an attribute to the switch case and write down the cases in it so that for each case value we can make desired statements to get executed. We can also define the cases with a range of values instead of a single value.
Contact Us