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

Home » Public Forums » archive » Re: "foreach" loops in IDL
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: "foreach" loops in IDL [message #64869 is a reply to message #64795] Tue, 20 January 2009 13:11 Go to previous messageGo to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Jan 16, 3:43 pm, Vince Hradil <vincehra...@gmail.com> wrote:
> I would have to agree with Paolo here.  The for-loop syntax is simple
> and clear.  The @do @done really obfuscates the code.

That's because it's an unsupported add-on. If IDL included foreach at
the language level, which would be clearer:

for i=0,n_elements(x)-1 do begin
elem=x[i]
print, my_function(elem)
end

or

foreach elem in x
print, my_function(elem)
end

When treating a vector as a list, requiring an extra loop variable is
pure syntactic overhead. Not to mention that the loop variable could
overflow, could get changed in the body of the loop or, most commonly,
risks nested sub-loops accidentally re-using the same loop variable.
None of these happens with a foreach construct.

JD
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: ERRPLOT using object Graphics .... ?
Next Topic: Contour command

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

Current Time: Fri Oct 10 02:27:55 PDT 2025

Total time taken to generate the page: 0.72143 seconds