Android Question Best way to delete items from a list using a for loop

andymc

Well-Known Member
Licensed User
Longtime User
If I am using a For next loop to cycle through a list, what's the best way to remove items from the list without having to exit the loop?

I generally do something like:
for x = 0 to myList.length - 1
myobject = mylist.get(x)
if myobject.value1 = 1 then
mylist.removeat(x)
exit
end if
next
 

andymc

Well-Known Member
Licensed User
Longtime User
Thanks Erel. I'm being a noob!

I need to really tidy up my space invaders game code, right now it's written just as I go without any real thoughts to optimisation, memory use or elegant code.
So now it's tidy up time!
 
Last edited:
Upvote 0

bparent

Member
Licensed User
Longtime User
Erel,,

Hello, thanks for your great products. I know this is a very old message, but I don't understand the code. I cannot find where a list has a Length property and myobject is not defined and doesn't have a value1 property?

Bernie
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I know this is a very old message
And that's exactly why you should always open a new thread.
I cannot find where a list has a Length property and myobject is not defined and doesn't have a value1 property?
A List type has a "size" property.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…