• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: if statements vs. switch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: if statements vs. switch
      • From: Ondra Cada <email@hidden>
    • Re: if statements vs. switch
      • From: ber <email@hidden>
    • Global notification when front process changes?
      • From: email@hidden (Patrick Beard)
References: 
 >Re: if statements vs. switch (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Encoding an integer in another object
  • Next by Date: Re: cString deprecated!
  • Previous by thread: Re: if statements vs. switch
  • Next by thread: Global notification when front process changes?
  • Index(es):
    • Date
    • Thread