There are many kinds of statements in the Java programming language. Most correspond to statements in the C and C++ languages, but some are unique.
As in C and C++, the
if statement of the Java programming language suffers from the so-called “dangling
else problem,” illustrated by this misleadingly formatted example:
if (door.isOpen()) if (resident.isVisible()) resident.greet("Hello!");else door.bell.ring(); // A "dangling else"
The problem is that both the outer
if statement and the inner
if statement might conceivably own the
else clause. In this example, one might surmise that the programmer intended the
else clause to belong to the outer
The Java programming language, like C and C++ and many programming ...