in reply to Re^3: if/else syntax
in thread if/else syntax
There's actually no ambiguity in the C syntax for your example. The compiler understands it fine. The problem is that the programmer/reader of the code does not always read it the same way.
if(a) if(b) c(); else d();
According to what I recall, the else matches with the nearest if in this case. Unfortunately, indentation gives humans fits on this.
if(a) if(b) c(); else d();
This does the same thing (else goes with if(b)). As I said, there's nothing ambiguous about it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: if/else syntax
by Anonymous Monk on Jun 26, 2009 at 17:01 UTC | |
Re^5: if/else syntax
by ikegami (Patriarch) on Jun 26, 2009 at 17:20 UTC | |
by massa (Hermit) on Jun 26, 2009 at 17:33 UTC | |
by gwadej (Chaplain) on Jun 29, 2009 at 13:34 UTC |