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
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
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
if
condition
if(condition)
{
statement1
;
statement2
;
..........
}
Stament1 and statement2 are conditional
their
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.
way2ITec
h
Outpu
t
Hello
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.
If(condition)
{
Statement
1;
Statement
2;
}
else
{
Statement
3;
way2ITec
h
way2ITec
h
Progra
m
• WAP to enter Small Case Character
And Output Upper Case Character
and When input character is Upper
case, Output small case character
way2ITec
h
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.
Progra
m
• WAP to find greatest of 3 numbers
using nested if-else
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.
• 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%
conditional.pptx
conditional.pptx

conditional.pptx