comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » assignment inside boolean expression
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: assignment inside boolean expression [message #20710 is a reply to message #20613] Tue, 18 July 2000 00:00 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
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 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 [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: optimization question: a faster way to PIXMAP?
Next Topic: Re: Top 10 IDL Requests

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 20:11:09 PDT 2025

Total time taken to generate the page: 0.64321 seconds