if (x > y)
x--;
else
y--;
This isn't the code used in my application, it's just for examples sake. A friend claimed this would be classified as a dangling else problem. As far as I know, and after looking it up for exact details on Wikipedia, it does not qualify as dangling else. What are your opinions?
That's not a dangling else. There's no ambiguity in that statement.
Quote from: Andy on February 13, 2009, 04:55 PM
That's not a dangling else. There's no ambiguity in that statement.
Exactly. Not sure why my friend wanted to consider it dangling else regardless what I said to him.
Andy's right, you're right, your friend is just dumb and obviously doesn't know simple C syntax. That's no dangling else.
There's my input on the subject, anyway.
Quote from: brew on February 13, 2009, 10:36 PM
Andy's right, you're right, your friend is just dumb and obviously doesn't know simple C syntax. That's no dangling else.
There's my input on the subject, anyway.
My friend is actually the most intelligent coder I know. He just gets practically OCD with things like this and tries explaining them with his own sometimes unusual point of view. Usually he's correct and I'm wrong, but with this one I'm sure it's the other way around.
A dangling else requires two possible if statements for the else to possibly apply to. Since your example has only one if statement, there is absolutely no question what the else belongs to. No contest.
C is quite clear about the grammar of if/else. Wikipedia (http://en.wikipedia.org/wiki/Dangling_else) uses BASIC as an illustrative demonstration of a dangling else.
Quote from: MyndFyre[vL] on February 14, 2009, 02:13 PM
C is quite clear about the grammar of if/else. Wikipedia (http://en.wikipedia.org/wiki/Dangling_else) uses BASIC as an illustrative demonstration of a dangling else.
Thanks. I also read that page prior to posting. That's as straightforward as it gets.