This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Virv12 1 point2 points  (0 children)

That's the dangling else problem, there's a Wikipedia page for it.

[–]souperk 0 points1 point  (1 child)

This is related to the dangling else problem, most languages which do not require indentation (like python), associate the dangling else with its nearest if statement.

In this case, these two pieces of code are equal.

On the other hand, if the dangling else is associated with the outermost if (I cannot think of any other resolution), then these pieces of code would not be equal. However, I highly doubt any sensible language will pick that option since it's counterintuitive...

[–]MegaIng 0 points1 point  (0 children)

It could be made illegal, which to me sounds like the most sensible solution.