Re: multiple choice IF condition
- To: mathgroup at smc.vnet.net
- Subject: [mg56449] Re: multiple choice IF condition
- From: dh <dh at metrohm.ch>
- Date: Tue, 26 Apr 2005 01:32:49 -0400 (EDT)
- References: <d4hvhj$1ha$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Mark, you may test if the variable i is in a given list like: MemberQ[{3,5,9,18},i] Further, "Do" is more appropriate than "Table" for your purpose, because you do not want to create a table but only the side effect. with this: Do[If[MemberQ[{3,5,9,18},i], a = a + i], {i, 20}] Sincerely, Daniel 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 >