Re: if statements vs. switch
Re: if statements vs. switch
- Subject: Re: if statements vs. switch
- From: Jeremy Dronfield <email@hidden>
- Date: Wed, 4 Sep 2002 17:08:44 +0100
On Wednesday, September 4, 2002, at 04:01 pm, Ondra Cada wrote:
Note also that you should consider a conditional expression, too. With
four possibilities it would not be the best solution, but with two
(sometimes even three) of them I would prefer it myself:
[myWindow setFrameTopLeftPoint:[prefs
integerForKey:@"ControlsDisplaySide"
]==0?top:bottom];
Thanks for your comments. I'm intrigued by your suggestion, because I've
often looked at conditional expressions like this in sample code,
feeling somehow that they looked useful, but I've never got to grips
with their syntax (I've never come across them in tutorial code, and
can't find them in the C docs I've got). Given that the call to defaults
in this example returns an integer, and that "top" and "bottom" are
pointers to NSPoints, what exactly is going on in "==0?top:bottom"? I'm
okay as far as ==0 (comparison between two integers) - it's the bit
after that which is bewildering. Just guessing, but with the first half
(before the question-mark) being a boolean expression, is the result
being used to pick a pointer from "top" or "bottom"? If so, how would a
three-possibility expression work?
(Sorry about all these slightly OT questions, but this stuff fascinates
me.)
-Jeremy
========================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at
http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.