Conditional Statements
Conditional Statements
Control statements enable us to specify the flow of program control; i.e., the order in which the
instructions in a program must be executed. They make it possible to make decisions, to perform
tasks repeatedly or to jump from one section of code to another.
Three main types of control flow in programming
D
I
S
C
O
U NO
N
T
if
if else
Decision
Making
Control Nested if else
structures
else if ladder
switch
Simple if statement
❖ It is a one way selection statement.
❖ If the Test Condition is true then true block gets executed.
Program to read the shopping amount and apply delivery charges if
the amount is less than 500.
if else
❖ It is a two way selection statement.
❖ If the Test Condition is True then true i.e. if block get executed.
❖ If the Test Condition is False then else block gets executed.
❖ In short either True block gets executed or False block gets executed not both
Program to read age and check if the candidate is eligible to Vote
or not
Program to read num & check if the given number is Even or Odd
discriminant = b * b - 4 * a * c;
return 0;
}