Valhalla Legends Archive

Programming => General Programming => Topic started by: Yegg on February 13, 2009, 04:00 PM

Title: Dangling else? --- your input
Post by: Yegg on February 13, 2009, 04:00 PM
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?
Title: Re: Dangling else? --- your input
Post by: Barabajagal on February 13, 2009, 04:55 PM
That's not a dangling else. There's no ambiguity in that statement.
Title: Re: Dangling else? --- your input
Post by: Yegg on February 13, 2009, 05:27 PM
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.
Title: Re: Dangling else? --- your input
Post by: 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.
Title: Re: Dangling else? --- your input
Post by: Yegg on February 13, 2009, 11:34 PM
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.
Title: Re: Dangling else? --- your input
Post by: Barabajagal on February 14, 2009, 12:25 AM
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.
Title: Re: Dangling else? --- your input
Post by: MyndFyre 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.
Title: Re: Dangling else? --- your input
Post by: Yegg on February 14, 2009, 06:14 PM
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.