Hey! Pssst! Wanna see something wierd? [message #8012] |
Fri, 31 January 1997 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Alright you IDL gurus. Explain this!
number = STRING(10)
FOR j=0, number DO PRINT, 'Cool...!'
Weird, huh. IDL reads my mind! :-)
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
2642 Bradbury Court, Fort Collins, CO 80521
Phone: 970-221-0438 Fax: 970-221-4762
E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
-----------------------------------------------------------
|
|
|
Re: Hey! Pssst! Wanna see something wierd? [message #8089 is a reply to message #8012] |
Mon, 03 February 1997 00:00  |
Andy Loughe
Messages: 174 Registered: November 1995
|
Senior Member |
|
|
David Fanning wrote:
>
> Alright you IDL gurus. Explain this!
>
> number = STRING(10)
> FOR j=0, number DO PRINT, 'Cool...!'
>
> Weird, huh. IDL reads my mind! :-)
>
Seems easy to explain, the string value is simply converted
to integer type because 0 is of that type, to prove this, try
these three options...
FOR j=0, number DO Help, j
FOR j=0L, number DO Help, j
FOR j=0., number DO Help, j
--
Andrew F. Loughe |
afl@cdc.noaa.gov
University of Colorado, CIRES Box 449 |
http://cdc.noaa.gov/~afl
Boulder, CO 80309-0449 | phn:(303)492-0707
fax:(303)497-7013
------------------------------------------------------------ ---------------
"I do not feel obliged to believe that the same God who has endowed us
with
sense, reason, and intellect has intended us to forego their use."
-Galileo
|
|
|
|
Re: Hey! Pssst! Wanna see something wierd? [message #8094 is a reply to message #8012] |
Mon, 03 February 1997 00:00  |
Joseph M Zawodny
Messages: 24 Registered: March 1996
|
Junior Member |
|
|
David Fanning wrote:
>
> Alright you IDL gurus. Explain this!
>
> number = STRING(10)
> FOR j=0, number DO PRINT, 'Cool...!'
>
> Weird, huh. IDL reads my mind! :-)
>
> David
Well since the loop variable of a FOR loop has the type of the
first parameter (namely whatever follows the equal sign) and all
other parameters (end-value and step-value) converted to the
same type, I am not surprised too much. The conversion of properly
formatted string variables to byte, integer, float, ... is well
known (look at READS function). I know this since I have had the
misfortune of expecting the following to work.
for k=0,123456789L do ...
for k=0,5,0.1 do ...
Neither of them worked as I expected until rewritten as
for k=0L,123456789 do ...
for k=0.,5,0.1 do ...
Have fun!
--
Work: Dr. Joseph M. Zawodny Play: Joe Zawodny
NASA Langley Research Center KO4LW@amsat.org
E-mail: J.M.Zawodny@LaRC.NASA.gov zawodny@exis.net
(757) 864-2681 (757) 864-2671 FAX http://wwwp.exis.net/~zawodny
|
|
|