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

Home » Public Forums » archive » Re: 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 #20612 is a reply to message #20609] Mon, 10 July 2000 00:00 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
Patrick Broos wrote:
> I was wondering if it's common knowlege that one can put an IDL
> assignment inside
> a boolean expression (like in the C language). For example
>
> if (v = 0) then ... assigns v and does not execute the "then"
> statement, while
> if (v = 1) then ... assigns v and does execute the then.
>
> Just as in C I find this leads to really nasty bugs.

Curious: I've never even considered using this syntax.

Enclosing a statement inside parentheses turns it into an expression,
which has a type and a value, e.g.

IDL> help, (v = 100)
<Expression> INT = 100

The variables in the right hand side of the statement must necessarily
be defined:
IDL> help, (zv = tv + vt)
% Variable is undefined: VT.
% Execution halted at: $MAIN$

If you take the following statements:

IDL> if (v = 0) then print, 'True'
IDL> help, v
V INT = 0

IDL> if (v = 1) then print, 'True'
True
IDL> help, v
V INT = 1

and remove the parentheses, the equivalent code is

IDL> v = 0
IDL> if (v) then print, 'True'
IDL> help, v
V INT = 0

IDL> v = 1
IDL> if (v) then print, 'True'
True
IDL> help, v
V INT = 1

Recall that in IDL, integers with odd non-zero values are Boolean
'True'. Beware of floats and doubles though, where any non-zero value is
Boolean 'True'.

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Standalone IDL applications?
Next Topic: Re: Writing GIF files in IDL ATTN: Paul van Delst, Liam Gumley

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

Current Time: Sat Oct 11 21:15:35 PDT 2025

Total time taken to generate the page: 2.15995 seconds