MathGroup Archive 2005

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

Search the Archive

Re: multiple choice IF condition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56467] Re: multiple choice IF condition
  • From: Peter Pein <petsie at arcor.de>
  • Date: Tue, 26 Apr 2005 01:33:46 -0400 (EDT)
  • References: <d4hvhj$1ha$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

marloo3 at mail15.com wrote:
> could we have a more practical way than this way of choosing some numbers of the 
> choice:
> 
> a = 0;
> Table[If[i == 3 || i == 5 || i == 9 || i==18, a = a + i], {i, 20}]
> 
> ie: i wish if it is possible like this:
> If[i==3 ||5 ||9||18, ...]
> 
> Thanks very much
> mark
> 
Hi Mark,

a = 0;
Table[Switch[i, 3 | 5 | 9 | 18, a += i, _, Null], {i, 20}]

produces the same Table

{Null, Null,    3, Null,    8, Null, Null, Null,   17, Null,
 Null, Null, Null, Null, Null, Null, Null,   35, Null, Null}

as in your example.

-- 
Peter Pein
Berlin


  • Prev by Date: Compile. Not again
  • Next by Date: Re: multiple choice IF condition
  • Previous by thread: Re: multiple choice IF condition
  • Next by thread: Re: multiple choice IF condition