Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » lists and sequences » Iterator » next
next | previous | forward | backward | up | index | toc

# next -- get the next object from an iterator

- Usage:
    `next x`
- Inputs:
  - x, a thing, an iterator;
- Outputs:
  - a thing, the next object from x;

## Description

This gets the next object from an iterator, i.e., something returned by iterator.

    i1 : iter = iterator {1, 2, 3}

    o1 = iter

    o1 : Iterator

    i2 : next iter

    o2 = 1

    i3 : next iter

    o3 = 2

    i4 : next iter

    o4 = 3

If the iterator is exhausted, then the symbol StopIteration is returned.

    i5 : next iter

    o5 = StopIteration

    o5 : Symbol

## See also

- Iterator -- class for iterators
- iterator -- get an iterator
- StopIteration -- stop iteration

## Ways to use next:

- `next(Iterator)`

## For the programmer

The object next is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Macaulay2Doc/doc_iterators.m2:138:0.