Gambas Documentation - /dev/api/cat/enum

/dev/api/cat/enum

# Enumeration Management

`GB.GetEnum` | Returns the current enumeration state.
`GB.ListEnum` | Lists all enumerators that enumerate a specified object.
`GB.NextEnum` | Returns the next enumerator.
`GB.StopAllEnum` | Stops all enumerators that enumerate a specified object.
`GB.StopEnum` | Stops the current enumeration.

## Overview

Enumerations are managed in the `_next` special method.

This method is called at the start of the enumeration, and at each loop iteration, to retrieve the first or the next element.

### Enumeration State

`GB.GetEnum` gives you a pointer to a enumeration buffer. Use this buffer to store the state of the enumeration. You can store up to 16 bytes into this buffer.

Note that the buffer is initialized with zeros at the beginning of the enumeration, so that you can detect when `_next` is called at the start of the enumeration.

When the end of the enumeration is reached, use the `GB.StopEnum` function to warn the interpreter, and returns immediately from the implementation function.

### Updating Enumeration State

If you destroy one element of the enumeration, you must use `GB.ListEnum` and `GB.NextEnum` to update the state of current iterators.

If you entirely clear the enumerable object, then you must use `GB.StopAllEnum` to stop all current iterators.