17db96d56Sopenharmony_ci.. highlight:: c
27db96d56Sopenharmony_ci
37db96d56Sopenharmony_ci.. _iterator-objects:
47db96d56Sopenharmony_ci
57db96d56Sopenharmony_ciIterator Objects
67db96d56Sopenharmony_ci----------------
77db96d56Sopenharmony_ci
87db96d56Sopenharmony_ciPython provides two general-purpose iterator objects.  The first, a sequence
97db96d56Sopenharmony_ciiterator, works with an arbitrary sequence supporting the :meth:`__getitem__`
107db96d56Sopenharmony_cimethod.  The second works with a callable object and a sentinel value, calling
117db96d56Sopenharmony_cithe callable for each item in the sequence, and ending the iteration when the
127db96d56Sopenharmony_cisentinel value is returned.
137db96d56Sopenharmony_ci
147db96d56Sopenharmony_ci
157db96d56Sopenharmony_ci.. c:var:: PyTypeObject PySeqIter_Type
167db96d56Sopenharmony_ci
177db96d56Sopenharmony_ci   Type object for iterator objects returned by :c:func:`PySeqIter_New` and the
187db96d56Sopenharmony_ci   one-argument form of the :func:`iter` built-in function for built-in sequence
197db96d56Sopenharmony_ci   types.
207db96d56Sopenharmony_ci
217db96d56Sopenharmony_ci
227db96d56Sopenharmony_ci.. c:function:: int PySeqIter_Check(op)
237db96d56Sopenharmony_ci
247db96d56Sopenharmony_ci   Return true if the type of *op* is :c:data:`PySeqIter_Type`.  This function
257db96d56Sopenharmony_ci   always succeeds.
267db96d56Sopenharmony_ci
277db96d56Sopenharmony_ci
287db96d56Sopenharmony_ci.. c:function:: PyObject* PySeqIter_New(PyObject *seq)
297db96d56Sopenharmony_ci
307db96d56Sopenharmony_ci   Return an iterator that works with a general sequence object, *seq*.  The
317db96d56Sopenharmony_ci   iteration ends when the sequence raises :exc:`IndexError` for the subscripting
327db96d56Sopenharmony_ci   operation.
337db96d56Sopenharmony_ci
347db96d56Sopenharmony_ci
357db96d56Sopenharmony_ci.. c:var:: PyTypeObject PyCallIter_Type
367db96d56Sopenharmony_ci
377db96d56Sopenharmony_ci   Type object for iterator objects returned by :c:func:`PyCallIter_New` and the
387db96d56Sopenharmony_ci   two-argument form of the :func:`iter` built-in function.
397db96d56Sopenharmony_ci
407db96d56Sopenharmony_ci
417db96d56Sopenharmony_ci.. c:function:: int PyCallIter_Check(op)
427db96d56Sopenharmony_ci
437db96d56Sopenharmony_ci   Return true if the type of *op* is :c:data:`PyCallIter_Type`.  This
447db96d56Sopenharmony_ci   function always succeeds.
457db96d56Sopenharmony_ci
467db96d56Sopenharmony_ci
477db96d56Sopenharmony_ci.. c:function:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel)
487db96d56Sopenharmony_ci
497db96d56Sopenharmony_ci   Return a new iterator.  The first parameter, *callable*, can be any Python
507db96d56Sopenharmony_ci   callable object that can be called with no parameters; each call to it should
517db96d56Sopenharmony_ci   return the next item in the iteration.  When *callable* returns a value equal to
527db96d56Sopenharmony_ci   *sentinel*, the iteration will be terminated.
53