One of the problems novice programmers are faced with is syntactic ambiguities such as the dangling-else problem, sometimes known as the hanging else. Dangling-else really just means that an optional else clause in a nested conditional structure becomes ambiguous. The original of the dangling else dates back to the design of the language ALGOL 60 which introduced the notion of two forms of the conditional if statement:
if expr then S1 if expr then S1 else S2
This was an unfortunate sequence of events, because it gave rise to inherent ambiguities in the code when nested statements were used. Consider the following piece of code:
if expr1 then if expr2 then S1 else S2
This can be interpreted one of two ways:
if expr1 then (if expr2 then S1 else S2)
if expr1 then (if expr2 then S1) else S2
Or course the compiler will interpret it the way it was designed to, which may or may not gel with how the algorithm has been designed. We associate the dangling else predominantly with C, however it exists in other languages. Pascal for example had a similar issue. Java, C++, all seem to be afflicted. Many of the languages that avoided the dangling-else, did so with the use of explicit end markers.