dangling else

Quick Reference

The ambiguity that arises if a language allows constructs of the form ifb1then ifb2thenS1elseS2 in which it is not clear which if is associated with the else. Algol 60 resolved the ambiguity by forbidding the use of if immediately after then; Pascal, C, C++, and Java associate the else with the innermost if. Ada avoids the problem by pairing each if with an explicit end if.

ifb1then ifb2thenS1elseS2

Subjects: Computing.

Reference entries