SlideShare a Scribd company logo
DECISION
STRUCTURES
THE IF-ELSE IF STATEMENT AND NESTED IF STATEMENTS IN C++
Presentators:
M. Tahir Bashir
Fahad Iftikhar
Bilal Ahmad
C++
@UMT 8-Apr-2016
CONDITIONAL STATEMENTS
• The C++ conditional statements are the:
• Therefore they are sometimes called selection statements
• Conditional statements give us the power to make basic decisions
• if statement
• if-else statement
• switch statement
• A conditional statement lets us choose which statement will be executed next
FLOW OF CONTROL
• Unless specified otherwise, the order of statement execution through a function is
linear: one statement after another in sequence
• Some programming statements allow us to:
• decide whether or not to execute a particular statement
• execute a statement over and over, repetitively
• These decisions are based on Boolean expressions (or conditions) that evaluate to
true or false
• The order of statement execution is called the flow of control
THE IF STATEMENT
• The if statement has the following syntax:
if ( condition )
statement;
if is a C++
reserved word
The condition must be a
Boolean expression. It must
evaluate to either true or false.
If the condition is true, the statement is executed.
If it is false, the statement is skipped.
LOGIC OF AN IF STATEMENT
condition
evaluated
statement
true
false
THE IF STATEMENT
• An example of an if statement:
if (FirstNo > SecondNo)
result = FirstNo - SecondNo;
cout<<"The resultant is"<< result;
• First the condition is evaluated -- the value of FirstNo is either greater than the
value of SecondNo, or it is not
• If the condition is true, the assignment statement is executed -- if it isn’t, it is
skipped.
• Either way, the call to cout is executed next
RELATIONAL OPERATORS
• A condition often uses one of C++'s equality operators or relational operators
== equal to
< less than
!= not equal to
• Note the difference between the equality operator (==) and the assignment
operator (=)
> greater than
<= less than or equal to
>= greater than or equal to
LOGICAL OPERATORS
• C++ provides logical operators.
• The binary logical operators combine two Boolean expressions into one.
• The unary logical operator switches the value of a Boolean expression.
• Binary logical operators have lower precedence than relational operators
• NOT has the same precedence as negation.
Operator Meaning Kind
&& AND Binary
|| OR Binary
! NOT Unary
LOGICAL NOT
• The logical NOT operation is also called logical negation or logical complement
• If some condition a is true, then !a is false; if a is false, then !a is true
• Logical expressions can be shown using a truth table
a !a
True False
False True
LOGICAL AND & LOGICAL OR
• The logical AND expression
a && b
is true if both a and b are true, and false otherwise
• The logical OR expression
a || b
is true if a or b or both are true, and false otherwise
IF-ELSE STATEMENT:
General form of an if-else statement:
if(BooleanExpression)
statement or block 1
else
statement or block 2
LOGIC OF AN IF-ELSE STATEMENT
condition
evaluated
statement1
true false
statement2
THE CONDITIONAL OPERATOR
• C++ provides and operator to create short expressions that work like if-else
statements.
BooleanExpression ? Value1 : Value2;
• If BooleanExpression is true, Value1 is returned
• If BooleanExpression is false, Value2 is returned
• Example:
if (score < 50)
cout<<“Sorry! You Have Failed…";
else
cout<<"You Have Successfully Passed! ";
THE IF-ELSE IF STATEMENT
• Sometimes you need to be able to test a series of conditions
• You can do this with the if-else if statement
• General form:
if (BooleanExpression1)
statement or block 1
else if (BooleanExpression2)
statement or block 2
else
statement or block 3
• If BooleanExpression1 is true, then statement or block 1 is executed.
• If BooleanExpression1 is false, then BooleanExpression2 is tested.
• If BooleanExpression2 is true, then statement or block 2 ais executed.
• If BooleanExpression2 is false, then statement or block 3 is executed.
Note: You can have as many if else clauses as is
needed.
NESTED IF STATEMENTS
• Nesting is enclosing one structure inside of another.
• A block in C++ can contain any valid C++ code, this includes other if statements:
if(BooleanExpression1) {
if(BooleanExpression2) {
statement1;
statement2;
}
statement3;
statement4;
}
• If BooleanExpression1 is true and BooleanExpression2 is true , what is executed?
• statement1 , statement2 , statement3 , statement4
• If BooleanExpression1 is true and BooleanExpression2 is false , what is executed?
• statement3 , statement4
THE END
ANY QUESTION
Ad

More Related Content

What's hot (20)

Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
sneha2494
 
Loops
LoopsLoops
Loops
Kulachi Hansraj Model School Ashok Vihar
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
Suneel Dogra
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
While loop
While loopWhile loop
While loop
Feras_83
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
Jin Castor
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
 
Loops in c
Loops in cLoops in c
Loops in c
baabtra.com - No. 1 supplier of quality freshers
 
Iteration
IterationIteration
Iteration
Liam Dunphy
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol28
 
Looping
LoopingLooping
Looping
Kulachi Hansraj Model School Ashok Vihar
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
Dr.Neeraj Kumar Pandey
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
Bangabandhu Sheikh Mujibur Rahman Science and Technology University
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
deekshagopaliya
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Priyom Majumder
 
Forloop
ForloopForloop
Forloop
Dipen Vasoya
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
Sriman Sawarthia
 
C++ loop
C++ loop C++ loop
C++ loop
Khelan Ameen
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
deekshagopaliya
 

Viewers also liked (17)

Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
Ahmad Idrees
 
1.4 core programming [understand error handling]
1.4 core programming [understand error handling]1.4 core programming [understand error handling]
1.4 core programming [understand error handling]
tototo147
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
Software Development Fundamentals
Software Development FundamentalsSoftware Development Fundamentals
Software Development Fundamentals
Chris Farrell
 
1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]
tototo147
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
Pranav Ghildiyal
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
Ilio Catallo
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
pratikborsadiya
 
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
Tech
 
Overview of c++
Overview of c++Overview of c++
Overview of c++
geeeeeet
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
samt7
 
Data structures / C++ Program examples
Data structures / C++ Program examplesData structures / C++ Program examples
Data structures / C++ Program examples
Kevin III
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
Deepak Singh
 
Loops in C
Loops in CLoops in C
Loops in C
Kamal Acharya
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
Ahmad Idrees
 
1.4 core programming [understand error handling]
1.4 core programming [understand error handling]1.4 core programming [understand error handling]
1.4 core programming [understand error handling]
tototo147
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
Software Development Fundamentals
Software Development FundamentalsSoftware Development Fundamentals
Software Development Fundamentals
Chris Farrell
 
1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]
tototo147
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
Pranav Ghildiyal
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
Ilio Catallo
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
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
Tech
 
Overview of c++
Overview of c++Overview of c++
Overview of c++
geeeeeet
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
samt7
 
Data structures / C++ Program examples
Data structures / C++ Program examplesData structures / C++ Program examples
Data structures / C++ Program examples
Kevin III
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
Deepak Singh
 
Ad

Similar to Understand Decision structures in c++ (cplusplus) (20)

Control structure
Control structureControl structure
Control structure
Samsil Arefin
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
Koteswari Kasireddy
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
baabtra.com - No. 1 supplier of quality freshers
 
Lewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_CodingLewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_Coding
GeorgeTsak
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
Anjali127411
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
NewsMogul
 
Control Structures, If..else, switch..case.pptx
Control Structures, If..else, switch..case.pptxControl Structures, If..else, switch..case.pptx
Control Structures, If..else, switch..case.pptx
doncreiz1
 
Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2
DanWooster1
 
intro to CONTROL STRUCTURES 1 for C++.pptx
intro to CONTROL STRUCTURES 1 for C++.pptxintro to CONTROL STRUCTURES 1 for C++.pptx
intro to CONTROL STRUCTURES 1 for C++.pptx
ragustilo27
 
C++ MAKING DECISION (IF IF/ELSE, SWITCH)
C++ MAKING DECISION (IF IF/ELSE, SWITCH)C++ MAKING DECISION (IF IF/ELSE, SWITCH)
C++ MAKING DECISION (IF IF/ELSE, SWITCH)
MelissaGuillermo1
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
Online
 
C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...
mshakeel44514451
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
ayshasafdarwaada
 
Conditonals.pdf
Conditonals.pdfConditonals.pdf
Conditonals.pdf
simrich7204
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
SzeChingChen
 
CSC111-Chap_03.pdf
CSC111-Chap_03.pdfCSC111-Chap_03.pdf
CSC111-Chap_03.pdf
2b75fd3051
 
class interview demo
class interview demo class interview demo
class interview demo
HELP4STUDENTS
 
python
pythonpython
python
HELP4STUDENTS
 
Demo for Class.pptx
 Demo for Class.pptx Demo for Class.pptx
Demo for Class.pptx
HELP4STUDENTS
 
Lewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_CodingLewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_Coding
GeorgeTsak
 
Control Structures, If..else, switch..case.pptx
Control Structures, If..else, switch..case.pptxControl Structures, If..else, switch..case.pptx
Control Structures, If..else, switch..case.pptx
doncreiz1
 
Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2
DanWooster1
 
intro to CONTROL STRUCTURES 1 for C++.pptx
intro to CONTROL STRUCTURES 1 for C++.pptxintro to CONTROL STRUCTURES 1 for C++.pptx
intro to CONTROL STRUCTURES 1 for C++.pptx
ragustilo27
 
C++ MAKING DECISION (IF IF/ELSE, SWITCH)
C++ MAKING DECISION (IF IF/ELSE, SWITCH)C++ MAKING DECISION (IF IF/ELSE, SWITCH)
C++ MAKING DECISION (IF IF/ELSE, SWITCH)
MelissaGuillermo1
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
Online
 
C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...
mshakeel44514451
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
ayshasafdarwaada
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
SzeChingChen
 
CSC111-Chap_03.pdf
CSC111-Chap_03.pdfCSC111-Chap_03.pdf
CSC111-Chap_03.pdf
2b75fd3051
 
class interview demo
class interview demo class interview demo
class interview demo
HELP4STUDENTS
 
Demo for Class.pptx
 Demo for Class.pptx Demo for Class.pptx
Demo for Class.pptx
HELP4STUDENTS
 
Ad

Recently uploaded (20)

Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdf
GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdfGENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdf
GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdf
Quiz Club of PSG College of Arts & Science
 
ITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQ
SONU HEETSON
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
materi 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblrmateri 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblr
fatikhatunnajikhah1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
The History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.pptThe History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.ppt
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...
UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...
UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...
businessweekghana
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-17-2025 .pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-17-2025  .pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-17-2025  .pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-17-2025 .pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Conditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture SlideConditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture Slide
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdfIPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
Quiz Club of PSG College of Arts & Science
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
ITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQ
SONU HEETSON
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
materi 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblrmateri 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblr
fatikhatunnajikhah1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...
UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...
UPSA JUDGEMENT.pdfCopyright Infringement: High Court Rules against UPSA: A Wa...
businessweekghana
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 

Understand Decision structures in c++ (cplusplus)

  • 1. DECISION STRUCTURES THE IF-ELSE IF STATEMENT AND NESTED IF STATEMENTS IN C++ Presentators: M. Tahir Bashir Fahad Iftikhar Bilal Ahmad C++ @UMT 8-Apr-2016
  • 2. CONDITIONAL STATEMENTS • The C++ conditional statements are the: • Therefore they are sometimes called selection statements • Conditional statements give us the power to make basic decisions • if statement • if-else statement • switch statement • A conditional statement lets us choose which statement will be executed next
  • 3. FLOW OF CONTROL • Unless specified otherwise, the order of statement execution through a function is linear: one statement after another in sequence • Some programming statements allow us to: • decide whether or not to execute a particular statement • execute a statement over and over, repetitively • These decisions are based on Boolean expressions (or conditions) that evaluate to true or false • The order of statement execution is called the flow of control
  • 4. THE IF STATEMENT • The if statement has the following syntax: if ( condition ) statement; if is a C++ reserved word The condition must be a Boolean expression. It must evaluate to either true or false. If the condition is true, the statement is executed. If it is false, the statement is skipped.
  • 5. LOGIC OF AN IF STATEMENT condition evaluated statement true false
  • 6. THE IF STATEMENT • An example of an if statement: if (FirstNo > SecondNo) result = FirstNo - SecondNo; cout<<"The resultant is"<< result; • First the condition is evaluated -- the value of FirstNo is either greater than the value of SecondNo, or it is not • If the condition is true, the assignment statement is executed -- if it isn’t, it is skipped. • Either way, the call to cout is executed next
  • 7. RELATIONAL OPERATORS • A condition often uses one of C++'s equality operators or relational operators == equal to < less than != not equal to • Note the difference between the equality operator (==) and the assignment operator (=) > greater than <= less than or equal to >= greater than or equal to
  • 8. LOGICAL OPERATORS • C++ provides logical operators. • The binary logical operators combine two Boolean expressions into one. • The unary logical operator switches the value of a Boolean expression. • Binary logical operators have lower precedence than relational operators • NOT has the same precedence as negation. Operator Meaning Kind && AND Binary || OR Binary ! NOT Unary
  • 9. LOGICAL NOT • The logical NOT operation is also called logical negation or logical complement • If some condition a is true, then !a is false; if a is false, then !a is true • Logical expressions can be shown using a truth table a !a True False False True
  • 10. LOGICAL AND & LOGICAL OR • The logical AND expression a && b is true if both a and b are true, and false otherwise • The logical OR expression a || b is true if a or b or both are true, and false otherwise
  • 11. IF-ELSE STATEMENT: General form of an if-else statement: if(BooleanExpression) statement or block 1 else statement or block 2
  • 12. LOGIC OF AN IF-ELSE STATEMENT condition evaluated statement1 true false statement2
  • 13. THE CONDITIONAL OPERATOR • C++ provides and operator to create short expressions that work like if-else statements. BooleanExpression ? Value1 : Value2; • If BooleanExpression is true, Value1 is returned • If BooleanExpression is false, Value2 is returned • Example: if (score < 50) cout<<“Sorry! You Have Failed…"; else cout<<"You Have Successfully Passed! ";
  • 14. THE IF-ELSE IF STATEMENT • Sometimes you need to be able to test a series of conditions • You can do this with the if-else if statement • General form: if (BooleanExpression1) statement or block 1 else if (BooleanExpression2) statement or block 2 else statement or block 3 • If BooleanExpression1 is true, then statement or block 1 is executed. • If BooleanExpression1 is false, then BooleanExpression2 is tested. • If BooleanExpression2 is true, then statement or block 2 ais executed. • If BooleanExpression2 is false, then statement or block 3 is executed. Note: You can have as many if else clauses as is needed.
  • 15. NESTED IF STATEMENTS • Nesting is enclosing one structure inside of another. • A block in C++ can contain any valid C++ code, this includes other if statements: if(BooleanExpression1) { if(BooleanExpression2) { statement1; statement2; } statement3; statement4; } • If BooleanExpression1 is true and BooleanExpression2 is true , what is executed? • statement1 , statement2 , statement3 , statement4 • If BooleanExpression1 is true and BooleanExpression2 is false , what is executed? • statement3 , statement4
  翻译: