Nested ifs
A nested if is an if statement which is the goal of another if or else. Nested ifs are extremely common in programming. Whenever you nest ifs, the major thing to remember is that an else statement always refers to the nearest if statement which is in the similar block as the else and which is not already related within an else. Here is an instance.
if (i ==10 ) {
if (j< 20) a=b;
if (k>100) c=d; / / this if is
else a =c; / / related along with this else
}
else a = d ; / / this else refers to if (i == 10)
As the comments denotes, the last else is not related with if (j<20,) since it is not in the similar block (even by it is the nearest if without an else.) relatively, the last else is related along with if (i==10). The inner else refers to if (k>100,) since it is the closes if in the similar block.