Nested if…else Statement

It is legitimate to home if-else constructs, which implies you can utilize one if or else if proclamation inside an alternate if or else if explanation. The syntax for using this construct Is as follows:

if (condition_1) {
  //Execute if condition_1 is true
  if (condition_2) {
    //Execute if condition_2 is true
  }
} else if (condition_3) {
  //Execute if condition_3 is true
} else {
  //Execute if all conditions are false
}

Sample Implementation:

public class myTest {
  public static void main(string args[]) {
    int i = 1;
    if (i >= 1) {
      System.out.println(“The
        if construct is executing!”);
      if (i == 1) {
        System.out.println(“The nested
          if construct is executing!”);
      }
    } else {
      System.out.print(“The
        else construct is executing!”);
    }
  }
}

This would create the accompanying result:

The if construct is executing!
The nested if construct is executing!