From 663f1d0f68dcc7b37a3c990922f076d91b4c58e7 Mon Sep 17 00:00:00 2001 From: eiffel-org Date: Mon, 30 Apr 2018 12:32:01 +0000 Subject: [PATCH] Update wikipage Iterate on a LIST and removing object. (Signed-off-by:tioui). git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2001 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- ...Iterate-on-a-LIST-and-removing-object.wiki | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterate-on-a-LIST-and-removing-object.wiki diff --git a/documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterate-on-a-LIST-and-removing-object.wiki b/documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterate-on-a-LIST-and-removing-object.wiki new file mode 100644 index 00000000..e2edd66e --- /dev/null +++ b/documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterate-on-a-LIST-and-removing-object.wiki @@ -0,0 +1,25 @@ +[[Property:uuid|78393BBA-9B1E-4523-9881-3D83CEB6A952]] +[[Property:weight|0]] +[[Property:title|Iterate on a LIST and removing object]] +If you already have the object that you want to remove from the LIST you can easily use prune and prune_all. But if you want to remove object while iterating on that LIST depending on criterions 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 recommand 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 LIST.remove. + +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 have this attribute set to True. Here what the code will look like. + + + removing_stopped(a_list:LIST[MY_CLASS]) + do + from + a_list.start + until + a_list.exhausted + loop + if a_list.item.has_stoped then + a_list.remove + else + a_list.forth + end + end + end + \ No newline at end of file