0% found this document useful (0 votes)
107 views

Conditional Statements in C++

This document discusses conditional expressions in C++. It covers if statements, if-else statements, nested if statements, and switch statements. If statements execute code if a boolean expression is true. If-else statements allow specifying else blocks to execute if the expression is false. Nested if statements can be used to check multiple conditions. Switch statements allow checking a variable against multiple values.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

Conditional Statements in C++

This document discusses conditional expressions in C++. It covers if statements, if-else statements, nested if statements, and switch statements. If statements execute code if a boolean expression is true. If-else statements allow specifying else blocks to execute if the expression is false. Nested if statements can be used to check multiple conditions. Switch statements allow checking a variable against multiple values.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lesson 7

CONDITIONAL
EXPRESSIONS IN C++

Conditional Expressions 1
CONDITIONAL EXPRESSIONS IN C++

• In C++ if statement is used to check the


truthness of the expression.
• Condition written inside If statement
consists of a boolean expression.
• If the condition is determined to be true,
and optionally, other statements to be
executed if the condition is determined to
be false.
Conditional Expressions 2
IF STATEMENT

• An ‘if’ statement consists of a boolean


expression followed by one or more
statements.
– if(boolean_expression)
–{
– // statement(s) will execute if the
– // boolean expression is true
–}

Conditional Expressions 3
IF STATEMENT

Conditional Expressions 4
IF...ELSE STATEMENT

• An ‘if’ statement can be followed by an


optional ‘else’ statement, which executes
when the boolean expression is false.
– if(boolean_expression)
– { // True Block
–}
– else
– { // False Block
–} Conditional Expressions 5
IF...ELSE STATEMENT

Conditional Expressions 6
NESTED IF STATEMENTS

• You can use one ‘if’ or ‘else if’ statement


inside another ‘if’ or ‘else if’ statement(s).
– if(boolean_expression 1) – else if( boolean_expression 3)
– { – {
– // When expression 1 is true – // When expression 3 is true
– } – }
– else if( boolean_expression 2) – else
– { – {
– // When expression 2 is true – // When none of expression is true
– } – }

Conditional Expressions 7
NESTED IF STATEMENTS

Conditional Expressions 8
SWITCH STATEMENT

• A ‘switch’ statement allows a variable to be


tested for equality against a list of values.
– switch(expression) – break;
–{ – case value3 :
– Body3
– case value1 :
– break;
– Body1 – default :
– break; – default-body
– case value2 : – break;
– body2 Conditional Expressions –} 9
SWITCH STATEMENT

Conditional Expressions 10
Thank you...

Conditional Expressions 11

You might also like