Suppose if you want to execute a block of statements after checking multiple conditions then nested if statement can be used.

Nested if is the extended form of if statements. It contains if statements at multiple level i.e if statements inside another if statements.

##### Syntax for nested if statements:
``````if (condition or expression)
{
if (condition1 or expression1)
{
conditional codes;
}
.
.
.
else
{
conditional codes;
}
.
.
.
statements;
}
.
.
.
else
{
if (condition2 or expression2)
{
conditional codes;
}
.
.
.
}
``````

In nested if statement first of all, outer condition of if statement is checked and if it is true then the condition of inner if statement is checked and if it is true then the conditional code is executed.

### Program example of nested if statement in C

``````//An example of nested if statement in C
#include<stdio.h>

int main()
{
int a = 10, b = 20, c = 5;
printf("Consider a = 10, b = 20 and c = 5\n");

if(a>b)
{
if(a>c)
{
printf("a is greater\n");
}
else
{
printf("c is greater\n");
}
}
else
{
if(b>c)
{
printf("b is greater\n";)
}
else
{
printf("c is greater\n");
}
}

printf("This is an example of nested if in C\n");
}

``````

### Output

``````Consider a = 10, b = 20 and c = 5
b is greater
This is an example of nested if in C
``````

In the above example we have three integer variables `a = 10, b = 20 and c = 5`. Here first of all the outer if statement is executed and condition is checked. For outer if statement our condition is `a>b`, since `a` is smaller than b so the condition is false and the if block is skipped. Now control is in else block. Now inside the else block there is nested if else statement. In the nested if statement our condition is `b>c`, since `b > c` so this block will be executed.