[Gambas-user] Accessing the nth item in a collection

Jussi Lahtinen jussi.lahtinen at ...626...
Thu Jun 5 02:39:42 CEST 2014


> In some languages, FOR EACH doesn't guaranty the order of the items
> processed. It only guaranties you will process each item in the collection.
> I think it is a bad habit to use For Each when order of processing is
> important.


I agree and that is not my requirement. I only need to know when order
changes (if Benoit changes the implementation). Example if I remove one
item, does the enumeration order of rest change? If not, I have no problems.



> Unless you are using an array or other data structure that is
> known to maintain order. A linked list or array would be a better choice. I
> haven't followed all this thread but I am sure that has already been
> suggested... The other option is to implement your own ordered collection.
> But wouldn't an array of object be easier?
>

I choose to use collection, because I have long list of objects and mostly
I need to access them individually and fast. If I would use array I would
have to enumerate them to find the object I wanted to access. Or constantly
update index table when object is removed.


Jussi



More information about the User mailing list