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

Home » Public Forums » archive » Foreach philosphy
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Foreach philosphy [message #73720] Wed, 24 November 2010 12:55
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
So I am trying to modernize my code by replacing FOR loops with the
FOREACH syntax when appropriate. That way one doesn't have to
worry about counting the number of elements, the code seems more
readable, and it even works for temporary arrays such as arr[*,
3,*].

But is it correct that you can't use the FOREACH syntax to update an
array? For example, is there way to use FOREACH for the
following code snippets?

IDL> for i=0,N_elements(a)-1 do a[i] = b[i]
or even
IDL> for i=0,N_elements(a)-1 do a[i] = 17

FOREACH doesn't give access to the counting index, and since array
elements are accessed by value, the following doesn't work

IDL> a = [1,2,3]
IDL> foreach element, a do element=17
IDL> print,a
1 2 3
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Questions about IDL 8.0
Next Topic: Re: Foreach philosphy

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

Current Time: Fri Oct 10 03:49:09 PDT 2025

Total time taken to generate the page: 1.19791 seconds