SlideShare una empresa de Scribd logo
1 de 20
Group member
• Manash Kumar Mondal
• Shariar Niloy
Types of if statement
What is if statement?
The if statement either selects an action, if a condition is
true or skips the action if the condition is false.
“If it is not raining, we will go to school.”
If ( conditional expression) {
statement_1;
statement_2;
statement_3;
}
#include <stdio.h>
int main(){
int a=5, b=10;
if(a<b)
printf("a is less than b n");
if(a>b)
printf("a is more than b n");
return 0;
}
a is less than b
Output
It allows you to specify that
different actions are to be
performed when the condition is
true and when it’s false.
If else
statement
Flow chart
if(expression){
Statement_1;
else
statement_2;
You entered an even numbera = 12
OutputInput
Nested loop?
If we use if else as a compound statement in another if else,
then it is called nested loop.
Nested loop
If (expression_1){
If(expression_2)
statement_1;
else
statement_2;
}
else {
if(expression_3)
statement_x;
}
Else if chain
A switch statement is a type of selection control
mechanism used to allow the value of a variable or
expression to change the control flow of program
execution via a multiway branch.
Switch
statement
Flow diagram
Limitations of switch over if-else ladder
1.The variable expression are also not allowed in
cases, ”case i+2:” is not allowed in switch, but it is
vaild on if-else.
2.You cannot test a flat expression using switch.
3.You cannot use similar expressions for multiple
cases.
4.Switch statement must know the value inside it
during compilation.
Advantages of switch over if-else ladder
1.A switch statement works much faster than equivalent if-else
ladder.
2.It is more readable and in compare to if-else statements.
3.It is more manageable for having higher level of indentation than if.
4. Here multiple statements need not to be enclosed within a pair of
braces.
Where to use
switch over if-
else ladder
1.If there are large number of
compares for a condition in your
program, use switch over if-else
ladder.
2.For more complex comparisons.
}
Where to use if-
else ladder over
switch
In case of simple and few
compares, if-else executes faster
and easy write. Thus as per
program’s requirement, a
programmer should decide
himself where to use which one
condition control.
Thank you….

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
The Loops
The LoopsThe Loops
The Loops
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Strings
StringsStrings
Strings
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Loops c++
Loops c++Loops c++
Loops c++
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Decision making in JAVA
Decision making in JAVADecision making in JAVA
Decision making in JAVA
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C if else
C if elseC if else
C if else
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 

Similar a If-else and switch-case

Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a program
Ysa Castillo
 

Similar a If-else and switch-case (20)

Intruduction conditional statement
Intruduction conditional statementIntruduction conditional statement
Intruduction conditional statement
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
What are conditional statements?
What are conditional statements?What are conditional statements?
What are conditional statements?
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
If else statement 05 (js)
If else statement 05 (js)If else statement 05 (js)
If else statement 05 (js)
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a program
 
conditional.pptx
conditional.pptxconditional.pptx
conditional.pptx
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Ch04
Ch04Ch04
Ch04
 
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
 

Más de Manash Kumar Mondal (9)

Apps in life
Apps in lifeApps in life
Apps in life
 
Invention that changed the world
Invention that changed the worldInvention that changed the world
Invention that changed the world
 
first order linear differential equation
first order linear differential equationfirst order linear differential equation
first order linear differential equation
 
Phonebook project in C
Phonebook project in CPhonebook project in C
Phonebook project in C
 
Java Calculator project
Java Calculator projectJava Calculator project
Java Calculator project
 
Processor
ProcessorProcessor
Processor
 
KVL & KCL
KVL & KCLKVL & KCL
KVL & KCL
 
Quantifier
QuantifierQuantifier
Quantifier
 
Do It Yourself
Do It YourselfDo It Yourself
Do It Yourself
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
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
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

If-else and switch-case

  • 1.
  • 2. Group member • Manash Kumar Mondal • Shariar Niloy
  • 3. Types of if statement
  • 4. What is if statement? The if statement either selects an action, if a condition is true or skips the action if the condition is false. “If it is not raining, we will go to school.”
  • 5. If ( conditional expression) { statement_1; statement_2; statement_3; }
  • 6. #include <stdio.h> int main(){ int a=5, b=10; if(a<b) printf("a is less than b n"); if(a>b) printf("a is more than b n"); return 0; } a is less than b Output
  • 7. It allows you to specify that different actions are to be performed when the condition is true and when it’s false. If else statement
  • 9. You entered an even numbera = 12 OutputInput
  • 10. Nested loop? If we use if else as a compound statement in another if else, then it is called nested loop.
  • 13. A switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via a multiway branch. Switch statement
  • 14.
  • 16. Limitations of switch over if-else ladder 1.The variable expression are also not allowed in cases, ”case i+2:” is not allowed in switch, but it is vaild on if-else. 2.You cannot test a flat expression using switch. 3.You cannot use similar expressions for multiple cases. 4.Switch statement must know the value inside it during compilation.
  • 17. Advantages of switch over if-else ladder 1.A switch statement works much faster than equivalent if-else ladder. 2.It is more readable and in compare to if-else statements. 3.It is more manageable for having higher level of indentation than if. 4. Here multiple statements need not to be enclosed within a pair of braces.
  • 18. Where to use switch over if- else ladder 1.If there are large number of compares for a condition in your program, use switch over if-else ladder. 2.For more complex comparisons. }
  • 19. Where to use if- else ladder over switch In case of simple and few compares, if-else executes faster and easy write. Thus as per program’s requirement, a programmer should decide himself where to use which one condition control.