[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*Subject*: Re: assignment inside boolean expression*From*: Martin Schultz <martin.schultz(at)dkrz.de>*Date*: Tue, 18 Jul 2000 17:45:59 +0200*Newsgroups*: comp.lang.idl-pvwave*Organization*: MPI fuer Meteorologie*References*: <396A3790.43C8EB31@astro.psu.edu> <396A429E.4367BEA9@ssec.wisc.edu> <396B18EE.DC2E38DD@seadas.bigelow.org> <ond7kkitqx.fsf@cow.physics.wisc.edu> <396B4656.BADDB2EE@seadas.bigelow.org>*Xref*: news.doit.wisc.edu comp.lang.idl-pvwave:20291

Ben Tupper wrote: > > Craig Markwardt wrote: > [...] > > Not to undercut you, but will (X AND 1) do the trick? > > > > Thanks to Ken and Craig. I think for my purposes the following should suffice (I > guess as long as I make sure that I'm working with an integer/long/byte type.) > > X = Indgen(6) - 2 > > For i = 0, N_elements(X)-1 Do $ > If X[i] then Print, X[i], ': Odd' Else print, X[i], ': Even' > > -2: Even > -1: Odd > 0: Even > 1: Odd > 2: Even > 3: Odd > > Thanks again, > > Ben but if you start increasing the number of elements of X to say 1000000, you are certainly better off with: answer=['even','odd'] print,answer[ (x and 1) ] no loop ;-) Example: IDL> x=lindgen(20)-5 IDL> answer=['even','odd'] IDL> print,answer[x and 1] odd even odd even odd even odd even odd even odd even odd even odd even odd even odd even BTW: X MOD 2 does not work for negative numbers !!! IDL> print,answer[x mod 2] even even even even even even odd even odd even odd even odd even odd even odd even odd even Cheers, Martin -- [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[ [[ Bundesstr. 55, 20146 Hamburg [[ [[ phone: +49 40 41173-308 [[ [[ fax: +49 40 41173-298 [[ [[ martin.schultz@dkrz.de [[ [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[

**References**:**assignment inside boolean expression***From:*Patrick Broos

**Re: assignment inside boolean expression***From:*Liam E.Gumley

**Re: assignment inside boolean expression***From:*Ben Tupper

**Re: assignment inside boolean expression***From:*Craig Markwardt

**Re: assignment inside boolean expression***From:*Ben Tupper

- Prev by Date:
**Re: Top 10 IDL Requests** - Next by Date:
**Re: Unix->Mac transition** - Prev by thread:
**Re: assignment inside boolean expression** - Next by thread:
**Re: assignment inside boolean expression** - Index(es):