Re: 'IN' statement in IDL [message #5342] |
Tue, 07 November 1995 00:00 |
korpela
Messages: 59 Registered: September 1993
|
Member |
|
|
In article <Pine.A32.3.91.951107091912.26059B-100000@zeus.cc.ucy.ac.cy>,
Frank Schnorrenberg <csfranks@zeus.cc.ucy.ac.cy> wrote:
>
> colors=['negative','weak','moderate','strong','very strong']
> FOR I=0, N_ELEMENTS(db) DO BEGIN
> FOR color IN colors DO BEGIN
>
> IF db(I).Color EQ color THEN ....
>
> ENDFOR
> ENDFOR
>
Maybe I don't quite understand what you're trying to do, but it seems
that the above code could be easily rewritten as:
------------------------------------------------------------ ------------
colors=['negative','weak','moderate','strong','very strong']
FOR I=0, N_ELEMENTS(db)-1 DO BEGIN
FOR J=0,N_ELEMENTS(colors)-1 DO BEGIN
IF db(I).Color EQ colors(J) THEN ....
ENDFOR
ENDFOR
------------------------------------------------------------ -------------
Personally, I would probably write it as:
------------------------------------------------------------ -------------
colors=['negative','weak','moderate','strong','very strong']
FOR I=0, N_ELEMENTS(db)-1 DO BEGIN
J=WHERE(colors eq db(I).Color)
if (J ne -1) THEN ....
ENDFOR
------------------------------------------------------------ -------------
Eric
--
Eric Korpela | An object at rest can never be
korpela@ssl.berkeley.edu | stopped.
<a href=" http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpe la/w">
Click here for more info.</a>
|
|
|