Learn C++ Language from the Best Tutors
Search in
How a switch statement works internally. That is how does it find which does it need to execute?
Switch is especially useful as check point for multiple conditions. Syntax: Switch(condition) { case 1: logic ;break; case 2 :logic; break; default : logic; } .switch statement checks condtion or choice and look for right case and execute the logic and then break the execution flow. if it did not find the any matched case , it will execute default block.
ex: int day=1;
switch(day){
case 1:
print("Monday");
break;
case 2:
print("Tuesday");
break;
case 1:
print("Wednesday");
break;
case 1:
print("Thursday");
break;
case 1:
print("Friday");
break;
case 1:
print("saturday");
break;
Default:
Print("Sunday");
}
result of condition is true or false we use if condition
When there are more than two options we use switch statement
compiler checks the case statement from top to down any case matches with the conditions it executes the blocks until break encounters other wise it edecutes default statements
read less
switch statement is a choice based selection statement
syntax:
switch(choice)
{
case 1:statements;
break;
case 2:statements;
break;
..
case value matching with the input value of choice will be executed.
case value can be integer or character
read lessView 2 more Answers
Related Questions
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
About C++ Programming Language
Introduction C++ is an excellent programming language and many of the applications are written in C++ language. It has generic, object-oriented & imperative programming features, and also provides facilities for low-level memory manipulation. Successor of C language, it is an OOP (object oriented programming) language...
What is Applications Engineering all about?
Applications engineering is a hot trend in the current IT market. An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...
Make a Career in Mobile Application Programming
Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...
Top 5 Skills Every Software Developer Must have
Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today. In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...
Looking for C++ Language Classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for C++ Language Classes are on UrbanPro
The best Tutors for C++ Language Classes are on UrbanPro