On jeudi 18 décembre 2008, Jussi Lahtinen wrote:
> Hi!
>
> I have code like this:
>
> Dim element as ClassX
>
> FOR EACH element IN objectarray
> IF element = something THEN
> objectarray.Remove(objectarray.Find(element))
> ENDIF
> NEXT
>
> This works, but I'm almost sure that there is better way to do this.
> Feel kind of dumb to find same element two times...
>
>
> Jussi
>

DO
  iInd = objectarray.Find(element)
  IF iInd < 0 THEN BREAK
  objectarray.Remove(iInd)
LOOP

Or:

iInd = 0
WHILE iInd < objectarray.Count
  IF objectarray[iInd] = element THEN
    objectarray.Remove(iInd)
  ELSE
    INC iInd
  ENDIF
WEND

-- 
Benoit Minisini

------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to