Re: multiple choice IF condition

• To: mathgroup at smc.vnet.net
• Subject: [mg56450] Re: [mg56427] multiple choice IF condition
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Tue, 26 Apr 2005 01:32:50 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```a=0;
Table[
If[i==3||i==5||i==9||i==18,a=a+i;],
{i,20}];
a

35

Alternatives:

a=0;
Table[
If[MemberQ[{3,5,9,18},i],a=a+i;],
{i,20}];
a

35

a=0;
Table[
{i,20}];
a

35

ClearAll[myIf];
SetAttributes[myIf, HoldAll];
myIf[i_Symbol==Or[val__],t_,f_:Null]:=

a=0;
Table[
myIf[i==Or[3,5,9,18],a=a+i;],
{i,20}];
a

35

Bob Hanlon

>
> From: marloo3 at mail15.com
To: mathgroup at smc.vnet.net
> Date: 2005/04/25 Mon AM 01:30:41 EDT
> Subject: [mg56450] [mg56427] multiple choice IF condition
>
> 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: odd mathematica blindspot
• Next by Date: Using BarChart in a Widget
• Previous by thread: Re: multiple choice IF condition
• Next by thread: Problem with MatchQ and SameQ