DeleteElement

List command

Syntax

Deletes the current element. The element before it becomes the current one.

DeleteElement(<list>() [, <flags>])

Parts

<list>A list declared with NewList, written with its empty parentheses: scores().
<flags>Optional, 0 by default. Any value other than 0 changes one case only: when the first element is deleted, the new first element becomes current instead of none.

Returns

1 when an element is current after the delete, 0 otherwise. Also 0, with nothing deleted, when there was no current element.

Good to know

  • Without <flags>, deleting the first element leaves no current element: ListIndex() returns -1, and the next NextElement() goes to the new first element.
  • Deleting inside FOREACH is safe: the loop goes on with the element that followed.
  • After FreeList(), the call stops the program with "BASIC list is not initialized".

Example

NewList a.integer()FOR k = 1 TO 3  AddElement(a())  a() = k * 10NEXTSelectElement(a(), 1)r = DeleteElement(a())Console(Str(r) + " " + Str(a()))   ' 1 10FirstElement(a())r = DeleteElement(a(), 1)Console(Str(r) + " " + Str(a()))   ' 1 30
In the manual : Arrays, lists and maps