Empty FOREACH loop [message #75108] |
Mon, 14 February 2011 15:47  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
I was quite surprised when the following raised an error for me:
IDL> foreach g, [] do help, g
% Variable is undefined: <UNDEFINED>.
% Execution halted at: $MAIN$
Does this seem like unexpected behavior? I was expecting the loop just
not to execute.
Of course, whatever the right answer is, it shouldn't do this (as it
does on my Mac):
IDL> foreach g, [] do help, g
% Temporary variables are still checked out - cleaning up...
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
|
Re: Empty FOREACH loop [message #81721 is a reply to message #75108] |
Mon, 15 October 2012 07:59  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
On 10/12/12 18:57, David Fanning wrote:
> rigby@crd.ge.com writes:
>
>> Think about the fun you'd have should you happen to misspell an honest-to-goodness defined variable :-)
>
> I agree. This would fall, along with silent error handlers,
> under my definition of Pure Evil if I were classifying it
> in a programming book. :-)
+1
In the context presented, I consider usage of undefined/non-existant
variables as a fundamental programming error.
It causes automatic failure of the "Good Citizen" test when reviewing
code submissions as a measure for granting write access to a repository.
Like going through a stop sign during your driving test. :o)
cheers,
paulv
|
|
|
Re: Empty FOREACH loop [message #81731 is a reply to message #75108] |
Fri, 12 October 2012 15:57  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
rigby@crd.ge.com writes:
> Think about the fun you'd have should you happen to misspell an honest-to-goodness defined variable :-)
I agree. This would fall, along with silent error handlers,
under my definition of Pure Evil if I were classifying it
in a programming book. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
|
|
|
Re: Empty FOREACH loop [message #81732 is a reply to message #75108] |
Fri, 12 October 2012 15:40  |
Bill Nel
Messages: 31 Registered: October 2010
|
Member |
|
|
On Friday, October 12, 2012 5:33:01 PM UTC-4, Dick Jackson wrote:
> IDL> foreach x, myUndefinedNonVariable do print,x
>
> % Variable is undefined: MYUNDEFINEDNONVARIABLE.
>
> Would anyone else agree that with no elements in myUndefinedNonVariable, this should quietly do no iterations?
>
> -Dick
Think about the fun you'd have should you happen to misspell an honest-to-goodness defined variable :-)
|
|
|