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

Home » Public Forums » archive » "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 #64867 is a reply to message #64806] Tue, 20 January 2009 14:57 Go to previous messageGo to previous message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Jan 20, 3:11 pm, JD Smith <jdtsmith.nos...@yahoo.com> wrote:
> 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

Oh, I agree - a foreach loop would be great to have in IDL. My only
point was that add-on is confusing to read, and I would prefer to
write more portable code that uses as much built in functionality as
possible.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: A new version of GRAFFER
Next Topic: Re: Problems with array elements as parameter in c++ function used via call_external

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

Current Time: Fri Oct 10 22:36:18 PDT 2025

Total time taken to generate the page: 0.40693 seconds