C – nested if statements

This statement allows the user to use if block inside the other if block. And the inner if statement is executed only if the outer if statement’s condition is true.

Syntax

Syntax of nested if statement in C:

if(condition1)
 {    
    //block of code to be executed    
    if(condition2)
    {  
      //block of code to be executed    
    }    
 } 

nested if Flowchart:

nested if

Example of nested if statement in C:

#include <stdio.h>

int main()
{
  // local variable
  int num1 = 60;
  int num2 = 90;

  // first if statement
  if (num1 > 50)
  {
    // if inside if statement
    if (num2 > 80)
    {
      printf("Actual value of num1 is : %d\n", num1);
      printf("Actual value of num2 is : %d\n", num2);
    }
  }

  return 0;
}

The output of nested if statement in C.

Actual value of num1 is : 60
Actual value of num2 is : 90