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

Re: assignment inside boolean expression



In article <396A3790.43C8EB31@astro.psu.edu>, Patrick Broos 
<patb@astro.psu.edu> 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.
> 
> 
> --
> ====================================================================
> Patrick S. Broos, Systems Analyst/Programmer    patb@astro.psu.edu
> 
> Department of Astronomy and Astrophysics  My office   814-863-7947
> Penn State University
> 525 Davey Lab                             FAX         814-863-8686
> University Park, PA  16802-6305
> http://www.astro.psu.edu                  Group office    863-9550
> ====================================================================
> 
> 
> 


The analogy with C only goes so far, it seems.

The following generates a syntax error:

   x = 0
   while ((x = x+1) lt 10) do print, x

whereas,

   x = 10.0
   while (x = x - 1.0) do print, x

produces:

      9.00000
      8.00000
      7.00000
      6.00000
      5.00000
      4.00000
      3.00000
      2.00000
      1.00000

-- 
  Jeffrey Jones
  Raytheon ITSS
  Code 975
  NASA/Goddard Space Flight Center
  Greenbelt, MD 20771 USA

office: Bldg 33, Rm A428
phone:  301.614.5721
email:  jeffrey.a.jones.1@gsfc.nasa.gov

-- 
Jeff

jajvj@erols.com