How to properly iterate over a display group and remove some of the display objects?

So I want to do the following thing:

  1. Create some display objects and add them to a group
  2. Move them each frame (during a single global enterFrame event)
  3. Remove some of the display objects (the ones that are off screen) from the group

The following code won’t work (since an object was removed and numChildren has changed):
[lua]local myDisplayObj = nil
for i=1, myGroup.numChildren do
myDisplayObj = myGroup[i]
if myDisplayObj.x > 1000 then
myDisplayObj:removeSelf()
end
end[/lua]

Any suggestions on how to do it nice and clean? [import]uid: 9536 topic_id: 6365 reply_id: 306365[/import]

Loop backwards:
http://developer.anscamobile.com/content/app-programming-guide#Common_Pitfalls [import]uid: 12108 topic_id: 6365 reply_id: 22007[/import]

simple and elegant, 10x [import]uid: 9536 topic_id: 6365 reply_id: 22543[/import]