That approach requires the For Each Number block, counting down from length of list by -1 in order to get the indices for the testing and removal by position.
Beware of the collapse of index numbers you would get if you traveled upwards while deleting items.
That would skip items.
Hi, I never studed coding or some programming language, but I like to learn , try and test.
I don't know the code inside the block but probably appinventor is ahead of normal people and know the most common errors made by people like me who don't have a solid foundation in computer science.
The code I used in the example works fine, probably because is a short list or probably because the block itself works in the way you showed us.
Maybe you or some power users know why it works.
Here the two codes I tried on the right side your hint ( I hope )
Both approaches "work", but the one on the right is safer, because it avoids reliance on undefined behavior.
The undefined behavior on the left relates to the For Each In List block.
How does it work when the list it is traversing crumbles under its feet?
Did it make a local copy of the list before it started?
Is it like a mountain climber, with pitons (pointers) driven into the next item on the list to save him from a landslide?
The AI2 docs don't say. I know AI2 lists are linked lists, based on my Ouroborous trick, but I don't know if they are singly or doubly linked lists.
It's best to avoid dangerous reliance on guesses, and to stick to well defined behaviors.
did you check the complete list after removing the items?
My guess is, item 6@ is still in the list, because you did not remove items as suggested... and for the other removed items you were lucky...
Thanks both @Taifun and @ABG to reply. As I said my code is wrong , didactically and for a beginner who want to learn how to write a right code.
Also I understand well what @ABG said to me and how index moving while code run.
yes I checked the complete list
I'm not lucky, I tried a lot of sequence
I was expecting an error but nothing , so I made another test and I saw how items go up when delete block run. The for each block count correctly 11 items even if they changed places. I will try other tests