SlideShare a Scribd company logo
1 of 7
Switch statement is a conditional statement, that allows us to
execute one block of code when the case matches.
What is switch statement?
You can do same thing with the if else if ladder. But switch seems to
be more simple. And does not complex overall program.
switch(expression)
{
case constant1:
//statements
break;
case constant2:
//statements
break;
default:
//default statements
}
Syntax of switch
1. switch is the keyword used to define switch statement
2. expression is any constant expression.
3. case is the keyword used to define different cases.
4. break is used to terminate the flow of execution after the
statements have been executed.
5. default is optional runs when none of them is executed.
switch
case 1
True
False
statements
break;
out of switch
case 2
True
False
statements
break;
default
default
statements
.
.
.
Let’s see an example on
switch statement
6 important points on switch case
1. The expression in the switch has to be evaluated as a constant value, so that
it can be compared with the case labels as an exact match.
2. The expression passed in the switch has to be an integral constant or a
character value only.
3. Break statement in the switch is used to terminate the sequence of execution.
5. Default statement is optional; it runs when there is no match with all the
cases.
4. Break is optional, you should include break after each case at the end of the
statement, if there will be no break all of the cases run after the match.
6. Nesting of switch can be done, which means switch under switch but we avoid
it as it makes the switch statement and program complex.
It’s the time!! Let’s make
Calculator

More Related Content

What's hot

Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in cMuthuganesh S
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
Conditionalstatement
ConditionalstatementConditionalstatement
ConditionalstatementRaginiJain21
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
Files in C
Files in CFiles in C
Files in CPrabu U
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programmingRumman Ansari
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Switch Case in C Program
Switch Case in C ProgramSwitch Case in C Program
Switch Case in C ProgramRup Chowdhury
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
 

What's hot (20)

Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
File in c
File in cFile in c
File in c
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
SWITCH CASE STATEMENT IN C
SWITCH CASE STATEMENT IN CSWITCH CASE STATEMENT IN C
SWITCH CASE STATEMENT IN C
 
Chapter 13 exceptional handling
Chapter 13 exceptional handlingChapter 13 exceptional handling
Chapter 13 exceptional handling
 
Files in C
Files in CFiles in C
Files in C
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Switch Case in C Program
Switch Case in C ProgramSwitch Case in C Program
Switch Case in C Program
 
Enums in c
Enums in cEnums in c
Enums in c
 
Looping statement
Looping statementLooping statement
Looping statement
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 

Similar to What is Switch Case?

Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)TejaswiB4
 
Lecture 7 Control Statements.pdf
Lecture 7 Control Statements.pdfLecture 7 Control Statements.pdf
Lecture 7 Control Statements.pdfSalmanKhurshid25
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition StructureShahzu2
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 
C language control statements
C language  control statementsC language  control statements
C language control statementssuman Aggarwal
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statementFarshidKhan
 
Chapter05-Control Structures.pptx
Chapter05-Control Structures.pptxChapter05-Control Structures.pptx
Chapter05-Control Structures.pptxAdrianVANTOPINA
 
Switch Statements.pptx
Switch Statements.pptxSwitch Statements.pptx
Switch Statements.pptxEnricoValdez3
 
SWITCH-CASE, Lesson Computer Programming.pptx
SWITCH-CASE, Lesson Computer Programming.pptxSWITCH-CASE, Lesson Computer Programming.pptx
SWITCH-CASE, Lesson Computer Programming.pptxAlwinJamesPuracan
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in javaAtul Sehdev
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Techglyphs
 
Control statements
Control statementsControl statements
Control statementsCutyChhaya
 

Similar to What is Switch Case? (20)

Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Lecture 7 Control Statements.pdf
Lecture 7 Control Statements.pdfLecture 7 Control Statements.pdf
Lecture 7 Control Statements.pdf
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
 
Chapter05-Control Structures.pptx
Chapter05-Control Structures.pptxChapter05-Control Structures.pptx
Chapter05-Control Structures.pptx
 
Switch Statements.pptx
Switch Statements.pptxSwitch Statements.pptx
Switch Statements.pptx
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
SWITCH-CASE, Lesson Computer Programming.pptx
SWITCH-CASE, Lesson Computer Programming.pptxSWITCH-CASE, Lesson Computer Programming.pptx
SWITCH-CASE, Lesson Computer Programming.pptx
 
C language 2
C language 2C language 2
C language 2
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1
 
Control statements
Control statementsControl statements
Control statements
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 

More from AnuragSrivastava272 (13)

What is recursion?
What is recursion? What is recursion?
What is recursion?
 
What is Do while loop?
What is Do while loop? What is Do while loop?
What is Do while loop?
 
What is while loop?
What is while loop?What is while loop?
What is while loop?
 
What is loops? What is For loop?
What is loops? What is For loop?What is loops? What is For loop?
What is loops? What is For loop?
 
What are conditional statements?
What are conditional statements?What are conditional statements?
What are conditional statements?
 
What are operators?
What are operators? What are operators?
What are operators?
 
What is Non-primitive data type?
What is Non-primitive data type?What is Non-primitive data type?
What is Non-primitive data type?
 
What is Data Types and Functions?
What is Data Types and Functions?What is Data Types and Functions?
What is Data Types and Functions?
 
What is Variables and Header files
What is Variables and Header filesWhat is Variables and Header files
What is Variables and Header files
 
What is IDE?
What is IDE?What is IDE?
What is IDE?
 
What is Platform Dependency?
What is Platform Dependency?What is Platform Dependency?
What is Platform Dependency?
 
What is Computer Language?
What is Computer Language? What is Computer Language?
What is Computer Language?
 
What is Language?
What is Language?What is Language?
What is Language?
 

Recently uploaded

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

What is Switch Case?

  • 1. Switch statement is a conditional statement, that allows us to execute one block of code when the case matches. What is switch statement? You can do same thing with the if else if ladder. But switch seems to be more simple. And does not complex overall program.
  • 2. switch(expression) { case constant1: //statements break; case constant2: //statements break; default: //default statements } Syntax of switch 1. switch is the keyword used to define switch statement 2. expression is any constant expression. 3. case is the keyword used to define different cases. 4. break is used to terminate the flow of execution after the statements have been executed. 5. default is optional runs when none of them is executed.
  • 3. switch case 1 True False statements break; out of switch case 2 True False statements break; default default statements . . .
  • 4. Let’s see an example on switch statement
  • 5. 6 important points on switch case 1. The expression in the switch has to be evaluated as a constant value, so that it can be compared with the case labels as an exact match. 2. The expression passed in the switch has to be an integral constant or a character value only. 3. Break statement in the switch is used to terminate the sequence of execution.
  • 6. 5. Default statement is optional; it runs when there is no match with all the cases. 4. Break is optional, you should include break after each case at the end of the statement, if there will be no break all of the cases run after the match. 6. Nesting of switch can be done, which means switch under switch but we avoid it as it makes the switch statement and program complex.
  • 7. It’s the time!! Let’s make Calculator