SlideShare a Scribd company logo
2
Most read
CONDITIONAL
STATEMENTS
CONDITIONAL STATEMENTS:
Conditional statements are used to make decisions based on a given condition. If the condition
evaluates to True, a set of statements is executed, otherwise another set of statements is executed.
And it is also known as decision statement.
There five types of conditional statements.
 if statement
 if else
 if else-if
 Switch statement
 Conditional operator
If statement:
If statement selects and executes the statement based on a given condition. If the condition evaluates
to True then a given set of statement is executed. However, if the condition evaluates to False, then
the given set of statement is skipped and the statement that are followed by if statement are executed.
For example:
x=6;
If(x>2)
{
cout<< x;
}
cout<< “x is an integer”;
If-else statement:
If-else statement comprises two parts, namely, if and else. If the condition is True, if part is executed.
However, if the condition is False, the else part is executed.
For example:
if(x>2)
{
cout<< “x is greater than 2”;
}
else
{
cout<< “x not greater than 2”;
}
IF ELSE-IF STATEMENT:
The if-else statement is used when we have two conditions. However, if we have more than two conditions or
choices, we used if else-if statement.
if (condition)
{
Statement(s);
}
else if (condition)
{
Statement(s);
}
else
{
Statement(s);
}
For example:
int x;
x=2;
if (x= = 0)
{
cout<< “it is equal to zero”;
}
else if (x>0)
{
cout<< “it is positive number”;
}
else
{
cout<< “it is negative number”;
}

More Related Content

PPTX
Programming (if else)
PPT
CHAPTER-3a.ppt
PPTX
Lec-5-IF-ELSE-SWITCH Programming Fundamentals.pptx
PDF
if else.pdf
PPTX
Conditional Statements in C.pptx
PPTX
Chapter 3 Conditional Statements&Looping (1).pptx
PPTX
Basics of Control Statement in C Languages
Programming (if else)
CHAPTER-3a.ppt
Lec-5-IF-ELSE-SWITCH Programming Fundamentals.pptx
if else.pdf
Conditional Statements in C.pptx
Chapter 3 Conditional Statements&Looping (1).pptx
Basics of Control Statement in C Languages

Similar to Conditional statements (20)

PDF
Programming Fundamentals Decisions
PPTX
IF & SWITCH (conditional control) in computer science
PPTX
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
PPT
Mesics lecture 6 control statement = if -else if__else
PPTX
conditional-statement.pptx for C++ TLE9
PPTX
Decision Controls in C++ Programming Lecture
PDF
control statement
PPTX
If Else Statement
PPTX
Introduction to Conditional Statements.pptx
PPTX
week 3 Programming lecture 05 (1) j.pptx
PPTX
Cs1123 5 selection_if
PPTX
Decision Making and Branching
PPTX
CPP programming Program Control Structures.pptx
PPTX
CONDITIONAL STRUCTURE(IF,IF-ELSE,ELSE-IF)COM.pptx
PPTX
Introduction to Selection control structures in C++
PPTX
Understand Decision structures in c++ (cplusplus)
PDF
Fundamentals of Computer Programming - Flow of Control I
PDF
C++ Chapter II
PDF
3 chapter three - part 1.pdf
PPTX
Control Statements and their use in C.pptx
Programming Fundamentals Decisions
IF & SWITCH (conditional control) in computer science
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
Mesics lecture 6 control statement = if -else if__else
conditional-statement.pptx for C++ TLE9
Decision Controls in C++ Programming Lecture
control statement
If Else Statement
Introduction to Conditional Statements.pptx
week 3 Programming lecture 05 (1) j.pptx
Cs1123 5 selection_if
Decision Making and Branching
CPP programming Program Control Structures.pptx
CONDITIONAL STRUCTURE(IF,IF-ELSE,ELSE-IF)COM.pptx
Introduction to Selection control structures in C++
Understand Decision structures in c++ (cplusplus)
Fundamentals of Computer Programming - Flow of Control I
C++ Chapter II
3 chapter three - part 1.pdf
Control Statements and their use in C.pptx
Ad

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PPTX
Introduction to Building Materials
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Empowerment Technology for Senior High School Guide
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Lesson notes of climatology university.
RMMM.pdf make it easy to upload and study
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Cell Types and Its function , kingdom of life
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Final Presentation General Medicine 03-08-2024.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
202450812 BayCHI UCSC-SV 20250812 v17.pptx
What if we spent less time fighting change, and more time building what’s rig...
Indian roads congress 037 - 2012 Flexible pavement
Unit 4 Skeletal System.ppt.pptxopresentatiom
Introduction to Building Materials
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Empowerment Technology for Senior High School Guide
Digestion and Absorption of Carbohydrates, Proteina and Fats
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
UNIT III MENTAL HEALTH NURSING ASSESSMENT
LDMMIA Reiki Yoga Finals Review Spring Summer
A systematic review of self-coping strategies used by university students to ...
Lesson notes of climatology university.
Ad

Conditional statements

  • 2. CONDITIONAL STATEMENTS: Conditional statements are used to make decisions based on a given condition. If the condition evaluates to True, a set of statements is executed, otherwise another set of statements is executed. And it is also known as decision statement. There five types of conditional statements.  if statement  if else  if else-if  Switch statement  Conditional operator
  • 3. If statement: If statement selects and executes the statement based on a given condition. If the condition evaluates to True then a given set of statement is executed. However, if the condition evaluates to False, then the given set of statement is skipped and the statement that are followed by if statement are executed. For example: x=6; If(x>2) { cout<< x; } cout<< “x is an integer”;
  • 4. If-else statement: If-else statement comprises two parts, namely, if and else. If the condition is True, if part is executed. However, if the condition is False, the else part is executed. For example: if(x>2) { cout<< “x is greater than 2”; } else { cout<< “x not greater than 2”; }
  • 5. IF ELSE-IF STATEMENT: The if-else statement is used when we have two conditions. However, if we have more than two conditions or choices, we used if else-if statement. if (condition) { Statement(s); } else if (condition) { Statement(s); } else { Statement(s); }
  • 6. For example: int x; x=2; if (x= = 0) { cout<< “it is equal to zero”; } else if (x>0) { cout<< “it is positive number”; } else { cout<< “it is negative number”; }