Dangling else problem
The problem is that the code is ambiguous. You can interpret it either as

If C1 then
   If C2 then
     S1
   else
     S2


or as

If C1 then
   If C2 then
     S1
else
   S2


The compiler needs to choose one way and covert it into machine language. The solution of "choose the last if" means the compiler will choose solution number 1 -- will attribute the "else" to the last (open, non-matched) "if" statement.