Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/rings/integer_ring_python.py
8817 views
1
def iterator(self):
2
r"""
3
Iterate over all integers: 0 1 -1 2 -2 3 -3 ...
4
5
This is the iterator for the integer ring `\ZZ`.
6
7
EXAMPLES::
8
9
sage: for n in ZZ: # indirect doctest
10
... if n < 3: print n
11
... else: break
12
0
13
1
14
-1
15
2
16
-2
17
"""
18
yield self(0)
19
n = self(1)
20
while True:
21
yield n
22
yield -n
23
n += 1
24
25
26