• Welcome to Valhalla Legends Archive.
 

Dangling else? --- your input

Started by Yegg, February 13, 2009, 04:00 PM

Previous topic - Next topic

Yegg

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?

Barabajagal

That's not a dangling else. There's no ambiguity in that statement.

Yegg

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.

brew

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.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Yegg

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.

Barabajagal

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.

MyndFyre

C is quite clear about the grammar of if/else.  Wikipedia uses BASIC as an illustrative demonstration of a dangling else.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Yegg

Quote from: MyndFyre[vL] on February 14, 2009, 02:13 PM
C is quite clear about the grammar of if/else.  Wikipedia 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.