Flow Control Statements in
C/C++
By: Er. Aman Kumar
Statement is instruction that
execute at run time
Type of statements
1. Sequential statement
2. Conditional statement
3. iterative/looping statement
4. Branching statement
way2ITech
Sequential statement
• These are those statements
which execute starting from
line1 to line 2 and so on.
• Till now the programs we
have done are example of
sequential statements as
lines/statements in
programs are executed in
the sequence as they are
written.
way2ITech
Conditional statement
• Are those statements which will depend on
condition for their execution.
Types of Conditional Statements
• If condition
• if-else condition
• Nested if-else
• If-else ladder
way2ITech
if condition
if(condition)
{
statement1;
statement2;
..........
}
Stament1 and statement2 are conditional
statements as they depend on condition for
their executing. way2ITech
WAP to find greatest of 2 numbers
using if condition
• lvalue : An expression that is an lvalue may
appear as either the left-hand or right-hand
side of an assignment.
way2ITech
Output
Hello
way2ITech
way2ITech
if-else condition
• if evaluates to true. It does nothing when
the expression evaluates to false.
• Else is used when we want some
statements to be executed when if
evaluates to be false. So if the condition
is true, if is executed else , else is
executed.
way2ITech
If(condition)
{
Statement1;
Statement2;
}
else
{
Statement3;
Statement4;
}
way2ITech
way2ITech
way2ITech
Program
• WAP to enter Small Case Character And
Output Upper Case Character and When
input character is Upper case, Output small
case character
way2ITech
way2ITech
Nested if-else
• if-else construct within either the body of the
if statement or the body of an else statement
or both. This is called nesting‘ of ifs.
way2ITech
way2ITech
Program
• WAP to find greatest of 3 numbers using
nested if-else
way2ITech
If-else Ladder
• It is used to check multiple conditions.
• Every else is associated with its previous
if.
• The last else goes to work only if all the
conditions fail.
• Even in else if ladder the last else is
optional.
way2ITech
way2ITech
• WAP to calculate tax for entered salary. If
salary > 10000, tax is 2 %. If salary lies
between 5000 and 10000, tax is 1.5 %. If
salary is in between 3000 to 5000 , Tax is 1 %
and if salary is lesser then 3000, Tax is 0%
way2ITech
way2ITech
9. statements (conditional statements)

9. statements (conditional statements)

  • 1.
    Flow Control Statementsin C/C++ By: Er. Aman Kumar
  • 2.
    Statement is instructionthat execute at run time Type of statements 1. Sequential statement 2. Conditional statement 3. iterative/looping statement 4. Branching statement way2ITech
  • 3.
    Sequential statement • Theseare those statements which execute starting from line1 to line 2 and so on. • Till now the programs we have done are example of sequential statements as lines/statements in programs are executed in the sequence as they are written. way2ITech
  • 4.
    Conditional statement • Arethose statements which will depend on condition for their execution. Types of Conditional Statements • If condition • if-else condition • Nested if-else • If-else ladder way2ITech
  • 5.
    if condition if(condition) { statement1; statement2; .......... } Stament1 andstatement2 are conditional statements as they depend on condition for their executing. way2ITech
  • 6.
    WAP to findgreatest of 2 numbers using if condition • lvalue : An expression that is an lvalue may appear as either the left-hand or right-hand side of an assignment. way2ITech
  • 7.
  • 8.
  • 9.
    if-else condition • ifevaluates to true. It does nothing when the expression evaluates to false. • Else is used when we want some statements to be executed when if evaluates to be false. So if the condition is true, if is executed else , else is executed. way2ITech
  • 10.
  • 11.
  • 12.
  • 13.
    Program • WAP toenter Small Case Character And Output Upper Case Character and When input character is Upper case, Output small case character way2ITech
  • 14.
  • 15.
    Nested if-else • if-elseconstruct within either the body of the if statement or the body of an else statement or both. This is called nesting‘ of ifs. way2ITech
  • 16.
  • 17.
    Program • WAP tofind greatest of 3 numbers using nested if-else way2ITech
  • 18.
    If-else Ladder • Itis used to check multiple conditions. • Every else is associated with its previous if. • The last else goes to work only if all the conditions fail. • Even in else if ladder the last else is optional. way2ITech
  • 19.
  • 20.
    • WAP tocalculate tax for entered salary. If salary > 10000, tax is 2 %. If salary lies between 5000 and 10000, tax is 1.5 %. If salary is in between 3000 to 5000 , Tax is 1 % and if salary is lesser then 3000, Tax is 0% way2ITech
  • 21.