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
  • Subject: [mg116713] Re: Which, Switch, If, and Piecewise
  • From: "Scot T. Martin" <smartin at>
  • Date: Fri, 25 Feb 2011 06:33:05 -0500 (EST)

>From my experience:

- PieceWise[..] is appropriate if your function will be used inside another numerical function, such as Integrate[...]

- Which[..] and Switch[..] are good for flow control in a program. Use whichever is more convenient for the type of flow control you want.

- If[..] is a scaled down version of Which[..] and Switch[..] that can be a
 great shortcut if your flow control needs are simple.

-----Original Message-----
From: Harvey P. Dale [mailto:hpd1 at]
Sent: Thursday, February 24, 2011 06:21
To: mathgroup at
Subject: [mg116713] [mg116684] Which, Switch, If, and Piecewise

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?

This email has been scanned by the MessageLabs Email Security System.
For more information please visit ________________________________________________________

  • Prev by Date: Re: How to deal with big matrix 2
  • Next by Date: Re: Bug in definite integral over Gamma function?
  • Previous by thread: Re: Which, Switch, If, and Piecewise
  • Next by thread: Simplification of equations