Re: Re: multiple choice IF condition

• To: mathgroup at smc.vnet.net
• Subject: [mg56495] Re: [mg56460] Re: [mg56427] multiple choice IF condition
• From: DrBob <drbob at bigfoot.com>
• Date: Tue, 26 Apr 2005 21:53:09 -0400 (EDT)
• References: <200504260533.BAA14401@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```How about this?

a=Tr@{3,5,9,18}

35

or this?

a=Total@{3,5,9,18}

35

or this?

a=Fold[Plus,0,{3,5,9,18}]

35

or this?

a=0;
(a += #)&/@Cases[Range@20,3|5|9|18];
a

35

or this?

a=0;
(a += #)&/@Cases[Range@20,Alternatives@@{3,5,9,18}];
a

35

Bobby

On Tue, 26 Apr 2005 01:33:15 -0400 (EDT), David Park <djmp at earthlink.net> wrote:

> Mark,
>
> a = 0;
> Table[If[MatchQ[i, 3 | 5 | 9 | 18], a = a + i], {i, 20}]
>
> David Park
>
> From: marloo3 at mail15.com [mailto:marloo3 at mail15.com]
To: mathgroup at smc.vnet.net
>
> 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
>
>
>
>
>
>
>

--
DrBob at bigfoot.com

```

• Prev by Date: Re: Compile. Not again
• Next by Date: Converting a mapping into a well-defined function
• Previous by thread: Re: multiple choice IF condition
• Next by thread: Re: multiple choice IF condition