Post Closed
16
Views
5
Comments
Solved
Como faço para excluir um item de uma lista que está sendo iterada?

Preciso manipular uma lista e retirar alguns itens de acordo com uma condicional, porém ao executar este código é exibido uma mensagem de erro.


mvp_badge
MVP
Solution

Hi Roberto,

First, this forum is an English language forum so people from all over the world can participate, so please translate your question into English.

Secondly, it seems you are doing a ListRemove on the list that the For Each is iterating over. This is not possible. You cannot modify a list that's being iteraterd. If you want to remove elements from a list, you have several choices:

  • Duplicate the list (use a ListDuplicate) and loop over the original list, ListRemoving from the duplicated list. This is not trivial, as the list keeps getting smaller so the corresponding index decreases with each removed element;
  • Use a ListFilter to remove at once all items you do not want. This may or may not be possible depending on what's inside your condition;
  • Instead of using a For Each, directly index the list, and ListRemove the elements you do not need.


Olá, Roberto.

Você poderia simplesmente usar o ListFilter. A ideia é que você vai criar uma segunda lista apenas com os itens que atendam a sua condição. 

Se isso não atender, você tem algumas outras opções mais complexas. Abraços!

PS:. Nós costumamos postar as dúvidas em inglês. Você pode usar o translater do google mesmo. 



mvp_badge
MVP

Hi Diel,

I already asked the OP to post in English, as this is an English language forum. Then you copy my answer (note I already opted for the ListFilter) using Portuguese, which is then marked as solution. Please don't do this again!


Why the downvotes? Please if you don't agree, reply :)

I think is something well known. You are in a community, you speak/ask for everyone to any language, not to a specific language. The community is not just Portuguese people, so that's why we ask and answer in English. Is not so difficult, you have easy ways to know what to write or read by using google translate, what is not missing is options. If you have any specific questions and there is another person speaking Portuguese, please do it privately.

And yes, @Kilian Hekhuis already said everything in his answer and people continues to spam the same answer every day. If there is something to add, please add it, but don't say the same thing that was already said.

https://www.outsystems.com/forums/discussion/27050/outsystems-community-code-of-conduct/

Kind Regards,

Márcio

mvp_badge
MVP
Solution

Hi Roberto,

First, this forum is an English language forum so people from all over the world can participate, so please translate your question into English.

Secondly, it seems you are doing a ListRemove on the list that the For Each is iterating over. This is not possible. You cannot modify a list that's being iteraterd. If you want to remove elements from a list, you have several choices:

  • Duplicate the list (use a ListDuplicate) and loop over the original list, ListRemoving from the duplicated list. This is not trivial, as the list keeps getting smaller so the corresponding index decreases with each removed element;
  • Use a ListFilter to remove at once all items you do not want. This may or may not be possible depending on what's inside your condition;
  • Instead of using a For Each, directly index the list, and ListRemove the elements you do not need.


Olá, Roberto.

Você poderia simplesmente usar o ListFilter. A ideia é que você vai criar uma segunda lista apenas com os itens que atendam a sua condição. 

Se isso não atender, você tem algumas outras opções mais complexas. Abraços!

PS:. Nós costumamos postar as dúvidas em inglês. Você pode usar o translater do google mesmo. 



mvp_badge
MVP

Hi Diel,

I already asked the OP to post in English, as this is an English language forum. Then you copy my answer (note I already opted for the ListFilter) using Portuguese, which is then marked as solution. Please don't do this again!


Why the downvotes? Please if you don't agree, reply :)

I think is something well known. You are in a community, you speak/ask for everyone to any language, not to a specific language. The community is not just Portuguese people, so that's why we ask and answer in English. Is not so difficult, you have easy ways to know what to write or read by using google translate, what is not missing is options. If you have any specific questions and there is another person speaking Portuguese, please do it privately.

And yes, @Kilian Hekhuis already said everything in his answer and people continues to spam the same answer every day. If there is something to add, please add it, but don't say the same thing that was already said.

https://www.outsystems.com/forums/discussion/27050/outsystems-community-code-of-conduct/

Kind Regards,

Márcio

Thank you all for the answer. Sorry to post it in portuguese.