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...
8 Hottest IT Careers of 2014!
Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...
Learn Hadoop and Big Data
Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...
Learn Microsoft Excel
Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...
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