SlideShare a Scribd company logo
1 of 33
LOGICAL EXPRESSIONS
 IF STATEMENT
SWITCH STATEMENT
Selection Statements
Flow of Control
 Unless specified , the order of statement execution
through a C program is linear: one statement after
the other, in sequence.
 Some programming statements modify that
order, allowing us to:
 decide whether or not to execute a particular statement, or
perform a statement over and over, repetitively
3
Flow of Control
 These decisions are based on a boolean Or logical
expression (also called a condition) that evaluates to
true or false
 The order of statement execution is called the flow of
control
Flow of Control
Sequential Flow
Flow of Control
Selection Statements
Flow of Control
Repetition
Logical Expression
 Logical expression is an expression which uses one
or more logical operators, e.g.,
 (temperature > 90.0 && humidity > 0.90)
 !(n <= 0 || n >= 100).
 The output of the logical expression is the boolean
value either true or false.
If Statements
 If statements consists of boolean expression followed
by one or more statements.
 If the boolean expression evaluates to true, the
statements inside the block get executed otherwise
the first statement outside the block get executed.
 The false value is o and all the other values are
evaluated as true in C.
If Statement
 The syntax of an If statement in C Program is given
below
If Statements
If Statement(Example)
Output
If…else Statement
 If statements can be followed by the optional else
statements, which get executed when the boolean
expression is false.
If…else Statement
If…else Statement(Example)
If…else Statement
If…elseif…else Statement
 If statement can be followed by optional elseif..else
statement, which is very useful to test various
conditions using single if…elseif statement.
 Following things should be kept in mind
 An if can have zero or one else's and it must come after any
else if's.
 An if can have zero to many else if's and they must come
before the else.
 Once an else if succeeds, none of the remaining else if's or
else's will be tested.
If…elseif…else Statement
If…elseif…else Statement(Example)
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 100;
if( a == 10 )
{
printf("Value of a is 10n" );
}
else if( a == 20 )
{
printf("Value of a is 20n" );
}
else if( a == 30 )
{
printf("Value of a is 30n" );
}
else
{
printf("None of the values is
matchingn" );
}
printf("Exact value of a is:
%dn", a );
getch();
return 0;
}
If…elseif…else Statement
Nested if Statements
 It is always legal in C programming to nest if-else
statements, which means we can use one if or else if
statement inside another if or else if statement(s).
Nested if Statements
#include <stdio.h>
#include <conio.h>
int main ()
{
int a = 100;
int b = 200;
if( a == 100 )
{
if( b == 200 )
{
printf("Value of a is 100
and b is 200n" );
}
}
printf("Exact value of a is :
%dn", a );
printf("Exact value of b is :
%dn", b );
getch();
return 0;
}
Nested if Statements
Switch Statement
 A switch statement allows a variable to be tested for
equality against a list of values.
 Each value is called a case, and the variable being
switched on is checked for each switch case.
 The following rules apply to a switch statement:
 The expression used in a switch statement must have an integral or
enumerated type, or be of a class type in which the class has a single
conversion function to an integral or enumerated type.
 You can have any number of case statements within a switch. Each
case is followed by the value to be compared to and a colon.
 The constant-expression for a case must be the same data type as the
variable in the switch, and it must be a constant or a literal.
Switch Statement
 When the variable being switched on is equal to a case, the
statements following that case will execute until a break
statement is reached.
 When a break statement is reached, the switch terminates, and
the flow of control jumps to the next line following the switch
statement.
 Not every case needs to contain a break. If no break
appears, the flow of control will fall through to subsequent
cases until a break is reached.
 A switch statement can have an optional default case, which
must appear at the end of the switch. The default case can be
used for performing a task when none of the cases is true. No
break is needed in the default case.
Switch Statement
Switch Statement
Switch Statement
#include <stdio.h>
#include <conio.h>
int main ()
{
char grade = 'B';
switch(grade)
{
case 'A' :
printf("Excellent!n" );
break;
case 'B' :
case 'C' :
printf("Well donen" );
break;
case 'D' :
printf("You passedn" );
break;
case 'F' :
printf("Better try againn" );
break;
default :
printf("Invalid graden" );
}
printf("Your grade is
%cn", grade );
getch();
return 0;
}
Switch Statement
Nested Switch Statements
 It is possible to have a switch as part of the statement
sequence of an outer switch.
 Even if the case constants of the inner and outer
switch contain common values, no conflicts will
arise.
Nested Switch Statements
Nested Switch Statements
#include <stdio.h>
#include <conio.h>
int main ()
{
int a = 100;
int b = 200;
switch(a)
{
case 100:
printf("This is part of outer
switchn", a );
switch(b)
{
case 200:
printf("This is part of inner
switchn", a );
}
}
printf("Exact value of a is : %dn", a
);
printf("Exact value of b is : %dn", b
);
getch();
return 0;
}
Nested Switch Statements

More Related Content

What's hot

Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaEdureka!
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
Instruction Execution Cycle
Instruction Execution CycleInstruction Execution Cycle
Instruction Execution Cycleutsav_shah
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programmingChitrank Dixit
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 

What's hot (20)

Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | Edureka
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Looping in C
Looping in CLooping in C
Looping in C
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Instruction Execution Cycle
Instruction Execution CycleInstruction Execution Cycle
Instruction Execution Cycle
 
K - Map
  K - Map    K - Map
K - Map
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Loops in C
Loops in CLoops in C
Loops in C
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 

Viewers also liked

Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Conditional Statements | If-then Statements
Conditional Statements | If-then StatementsConditional Statements | If-then Statements
Conditional Statements | If-then Statementssheisirenebkm
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)Way2itech
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
The Switch Statement in java
The Switch Statement in javaThe Switch Statement in java
The Switch Statement in javaTalha Saleem
 
Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011jbcmertens
 
說話的藝術
說話的藝術說話的藝術
說話的藝術qfaycho
 
Life in 1500 History Lesson 1
Life in 1500 History Lesson 1Life in 1500 History Lesson 1
Life in 1500 History Lesson 1Michael Foong
 
Nieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHDNieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHDlinuspauling
 
Concentratiestoornissen
ConcentratiestoornissenConcentratiestoornissen
ConcentratiestoornissenStershop BV
 
Relatie en oplossingsgericht werken (Updated Version - 2013)
Relatie  en oplossingsgericht werken (Updated Version - 2013)Relatie  en oplossingsgericht werken (Updated Version - 2013)
Relatie en oplossingsgericht werken (Updated Version - 2013)Philippe Bailleur
 

Viewers also liked (20)

Selection statements
Selection statementsSelection statements
Selection statements
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Conditional Statements | If-then Statements
Conditional Statements | If-then StatementsConditional Statements | If-then Statements
Conditional Statements | If-then Statements
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
 
The Switch Statement in java
The Switch Statement in javaThe Switch Statement in java
The Switch Statement in java
 
Iteration
IterationIteration
Iteration
 
Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011
 
Seminar Time Management
Seminar Time ManagementSeminar Time Management
Seminar Time Management
 
說話的藝術
說話的藝術說話的藝術
說話的藝術
 
Life in 1500 History Lesson 1
Life in 1500 History Lesson 1Life in 1500 History Lesson 1
Life in 1500 History Lesson 1
 
National income
National incomeNational income
National income
 
Nieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHDNieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHD
 
Concentratiestoornissen
ConcentratiestoornissenConcentratiestoornissen
Concentratiestoornissen
 
Relatie en oplossingsgericht werken (Updated Version - 2013)
Relatie  en oplossingsgericht werken (Updated Version - 2013)Relatie  en oplossingsgericht werken (Updated Version - 2013)
Relatie en oplossingsgericht werken (Updated Version - 2013)
 
Time management
Time managementTime management
Time management
 

Similar to Selection Statements in C Programming

C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c languagechintupro9
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docxJavvajiVenkat
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
C programming decision making
C programming decision makingC programming decision making
C programming decision makingSENA
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, LoopingMURALIDHAR R
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Neeru Mittal
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 

Similar to Selection Statements in C Programming (20)

C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 

More from Kamal Acharya

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer SecurityKamal Acharya
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHPKamal Acharya
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in phpKamal Acharya
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPKamal Acharya
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data WarehousingKamal Acharya
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data MiningKamal Acharya
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data MiningKamal Acharya
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data miningKamal Acharya
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingKamal Acharya
 

More from Kamal Acharya (20)

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Computer Arithmetic
Computer ArithmeticComputer Arithmetic
Computer Arithmetic
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer Security
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Web forms in php
Web forms in phpWeb forms in php
Web forms in php
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data Warehousing
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Search Engines
Search EnginesSearch Engines
Search Engines
 
Web Mining
Web MiningWeb Mining
Web Mining
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data Mining
 
Cluster Analysis
Cluster AnalysisCluster Analysis
Cluster Analysis
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data Mining
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
 

Recently uploaded

ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

Recently uploaded (20)

ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

Selection Statements in C Programming

  • 1. LOGICAL EXPRESSIONS  IF STATEMENT SWITCH STATEMENT Selection Statements
  • 2. Flow of Control  Unless specified , the order of statement execution through a C program is linear: one statement after the other, in sequence.  Some programming statements modify that order, allowing us to:  decide whether or not to execute a particular statement, or perform a statement over and over, repetitively
  • 3. 3 Flow of Control  These decisions are based on a boolean Or logical expression (also called a condition) that evaluates to true or false  The order of statement execution is called the flow of control
  • 7. Logical Expression  Logical expression is an expression which uses one or more logical operators, e.g.,  (temperature > 90.0 && humidity > 0.90)  !(n <= 0 || n >= 100).  The output of the logical expression is the boolean value either true or false.
  • 8. If Statements  If statements consists of boolean expression followed by one or more statements.  If the boolean expression evaluates to true, the statements inside the block get executed otherwise the first statement outside the block get executed.  The false value is o and all the other values are evaluated as true in C.
  • 9. If Statement  The syntax of an If statement in C Program is given below
  • 13. If…else Statement  If statements can be followed by the optional else statements, which get executed when the boolean expression is false.
  • 17. If…elseif…else Statement  If statement can be followed by optional elseif..else statement, which is very useful to test various conditions using single if…elseif statement.  Following things should be kept in mind  An if can have zero or one else's and it must come after any else if's.  An if can have zero to many else if's and they must come before the else.  Once an else if succeeds, none of the remaining else if's or else's will be tested.
  • 19. If…elseif…else Statement(Example) #include <stdio.h> #include<conio.h> int main () { int a = 100; if( a == 10 ) { printf("Value of a is 10n" ); } else if( a == 20 ) { printf("Value of a is 20n" ); } else if( a == 30 ) { printf("Value of a is 30n" ); } else { printf("None of the values is matchingn" ); } printf("Exact value of a is: %dn", a ); getch(); return 0; }
  • 21. Nested if Statements  It is always legal in C programming to nest if-else statements, which means we can use one if or else if statement inside another if or else if statement(s).
  • 22. Nested if Statements #include <stdio.h> #include <conio.h> int main () { int a = 100; int b = 200; if( a == 100 ) { if( b == 200 ) { printf("Value of a is 100 and b is 200n" ); } } printf("Exact value of a is : %dn", a ); printf("Exact value of b is : %dn", b ); getch(); return 0; }
  • 24. Switch Statement  A switch statement allows a variable to be tested for equality against a list of values.  Each value is called a case, and the variable being switched on is checked for each switch case.  The following rules apply to a switch statement:  The expression used in a switch statement must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type.  You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon.  The constant-expression for a case must be the same data type as the variable in the switch, and it must be a constant or a literal.
  • 25. Switch Statement  When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.  When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.  Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached.  A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.
  • 28. Switch Statement #include <stdio.h> #include <conio.h> int main () { char grade = 'B'; switch(grade) { case 'A' : printf("Excellent!n" ); break; case 'B' : case 'C' : printf("Well donen" ); break; case 'D' : printf("You passedn" ); break; case 'F' : printf("Better try againn" ); break; default : printf("Invalid graden" ); } printf("Your grade is %cn", grade ); getch(); return 0; }
  • 30. Nested Switch Statements  It is possible to have a switch as part of the statement sequence of an outer switch.  Even if the case constants of the inner and outer switch contain common values, no conflicts will arise.
  • 32. Nested Switch Statements #include <stdio.h> #include <conio.h> int main () { int a = 100; int b = 200; switch(a) { case 100: printf("This is part of outer switchn", a ); switch(b) { case 200: printf("This is part of inner switchn", a ); } } printf("Exact value of a is : %dn", a ); printf("Exact value of b is : %dn", b ); getch(); return 0; }