[Gambas-user] Accessing the nth item in a collection
B Bruen
bbruen at ...2308...
Wed Jun 4 02:22:54 CEST 2014
Occasionally, and unfortunately for me lately quite frequently, I have found a need to access the first or last item in (or perhaps better "the first or last item added to") a collection regardless of key values (and by extension I could envisage a need to access the nth item in a collection regardless of the key value). There does not seem to be an elegant solution to this - or maybe just that I am incapable of developing an elegant solution to this.
"First" can be achieved by using the For Each construct and unconditionally Break'ing the iteration on the first loop. This smells like using a sledge hammer to crush an ant.
"Last" I have achieved after a manner, but the mechanism is too embarrassing to reveal.
"nth" I am reluctant to attempt.
Any clues?
--
B Bruen <bbruen at ...2308...>
More information about the User
mailing list