Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Which, Switch, If, and Piecewise

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116725] Re: Which, Switch, If, and Piecewise
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 25 Feb 2011 06:35:15 -0500 (EST)

Use the one that's more readable.

If you're testing for several values of the same expression, that would be  
Switch; it evaluates the expression only once.

If you're testing for several mutually exclusive conditions, use Which.

If you're testing one condition, use If.

Bobby

On Thu, 24 Feb 2011 05:20:42 -0600, Harvey P. Dale <hpd1 at nyu.edu> wrote:

> What are the pros and cons among Which, Switch, If, and
> Piecewise?  When should one use one rather than the others?  Is one
> usually faster?  Is one easier to compile?
> Thanks,
> Harvey
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Pattern Matching Question
  • Next by Date: Images made from ColorFunction-supplied Rasters
  • Previous by thread: Which, Switch, If, and Piecewise
  • Next by thread: Re: Which, Switch, If, and Piecewise