Nested if else statement
syntax
If(test condition1)
{
If(test condition2);
{
Statement1;
}
Else
{
Statement2
}
Else
{
Statement 3
}
Statement –x
If the test expression can be executed first if it is true then true block can be executed immediately
following if statement are executed otherwise false statement are executed
if neither case they statement x can be executed
Eg:
If(sex is female)
{
If(bal<500O)
Bonus=.05*bal;
Else
Bonus=.02*bal;
Bal=bal+bonus;
Program:
Main()
{
Int a,b,c;
Printf(“enter the value”);
Scanf(“%d%d%d”,&a,&b,&c);
If(a>b)
{
If(a>c)
Printf(“%d”,a);
Else
Printf(“%d”,c);
}
Else
{
If(c>b)
Printf(“%d”,c);
Else
Printf(“%d”,b);
}
}
syntax
If(test condition1)
{
If(test condition2);
{
Statement1;
}
Else
{
Statement2
}
Else
{
Statement 3
}
Statement –x
If the test expression can be executed first if it is true then true block can be executed immediately
following if statement are executed otherwise false statement are executed
if neither case they statement x can be executed
Eg:
If(sex is female)
{
If(bal<500O)
Bonus=.05*bal;
Else
Bonus=.02*bal;
Bal=bal+bonus;
Program:
Main()
{
Int a,b,c;
Printf(“enter the value”);
Scanf(“%d%d%d”,&a,&b,&c);
If(a>b)
{
If(a>c)
Printf(“%d”,a);
Else
Printf(“%d”,c);
}
Else
{
If(c>b)
Printf(“%d”,c);
Else
Printf(“%d”,b);
}
}