SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
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 CSowmya Jyothi
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programmingRabin BK
 
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 programmingPriyansh Thakar
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C BUBT
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming Kamal Acharya
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 

La actualidad más candente (20)

Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
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
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
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
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Operators
OperatorsOperators
Operators
 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Branching in C
Branching in CBranching in C
Branching in C
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Storage class
Storage classStorage class
Storage class
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 

Destacado

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
 
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
 
System Analysis and Design slides by yared yenealem DTU Ethiopia
System Analysis and Design slides by yared yenealem DTU EthiopiaSystem Analysis and Design slides by yared yenealem DTU Ethiopia
System Analysis and Design slides by yared yenealem DTU EthiopiaDebre Tabor University
 

Destacado (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)
 
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
 
System Analysis and Design slides by yared yenealem DTU Ethiopia
System Analysis and Design slides by yared yenealem DTU EthiopiaSystem Analysis and Design slides by yared yenealem DTU Ethiopia
System Analysis and Design slides by yared yenealem DTU Ethiopia
 

Similar a 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
 
03a control structures
03a   control structures03a   control structures
03a control structuresManzoor ALam
 

Similar a 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
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
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
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 
03a control structures
03a   control structures03a   control structures
03a control structures
 

Más de 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
 

Más de 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
 

Último

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Último (20)

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

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; }