MathGroup Archive 2005

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

Search the Archive

Re: multiple choice IF condition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56438] Re: [mg56427] multiple choice IF condition
  • From: yehuda ben-shimol <bsyehuda at gmail.com>
  • Date: Tue, 26 Apr 2005 01:32:39 -0400 (EDT)
  • References: <200504250530.BAA01448@smc.vnet.net>
  • Reply-to: yehuda ben-shimol <bsyehuda at gmail.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Do you really want to use Table for this case? Since it will return
Null for values of i that do not match the condidion. I believe that
Do[] will be better since the type of programming points that you are
interested with the value of a .
As for your question, there is a way
a=0;Table[If[Or @@ Thread[i == {3, 5, 9, 18}], a = a + i], {i, 20}]
or better
a=0;Do[If[Or @@ Thread[i == {3, 5, 9, 18}], a = a + i], {i, 20}]
After all it seems that you need to sum a list of numbers and there
are better ways of doing it.
If you use version 5.1
a=Total[{3,5,9,18}]
or 
a=Plus@@{3,5,9,18} 
for earlier versions
yehuda
On 4/25/05, marloo3 at mail15.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
> 
>


  • Prev by Date: Re: diagonalizzation routine
  • Next by Date: Re: Problem with MatchQ and SameQ
  • Previous by thread: Re: multiple choice IF condition
  • Next by thread: Re: multiple choice IF condition