Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hanging else problem?

Tags:

c++

pascal

What is the "hanging else" problem? (Is that the right name?)

Following a C++ coding standard (forgot which one) I always use brackets (block) with control structures. So I don't normally have this problem (to which "if" does the last(?) else belong), but for understanding possible problems in foreign code it would be nice with a firm understanding of this problem. I remember reading about it in a book about Pascal many years ago, but I can't find that book.

like image 844
Peter Mortensen Avatar asked Dec 03 '22 07:12

Peter Mortensen


1 Answers

Ambiguous else.

Some info here: http://theory.stanford.edu/~amitp/yapps/yapps-doc/node3.html

But the classic example is:

if a then
  if b then
     x = 1;
  else 
     y = 1;

vs.

if a then
  if b then
     x = 1;
else 
  y = 1;
like image 69
Joe Avatar answered Dec 18 '22 15:12

Joe