- 18.01 (released) ...
Removing object while iterating on a LIST
If you already have the object that you want to remove from the
LIST you can easily use
prune_all. But if you want to remove objects while iterating on that
LIST, depending on criteria on the objects contained in the
LIST, here what you can do.
First of all, if you think about removing object while iterating, I do not recommend using an
across loop. If you iterate on the list using a
from until loop end, just remember to use the
LIST.forth only when you do not use
For example, let's say we have class
MY_CLASS with an attribute
has_stopped and that I want to remove every object of a
LIST that has this attribute set to
True. Here what the code will look like.
-- Removing every closed element of `a_list'
if a_list.item.has_stoped then