D
Doug Rosser
class Cycle(object):
def __init__(self, inputList):
object.__init__(self)
self.index = 0
self.limit = len(inputList)
self.list = inputList
def next(self):
"""
returns the next element of self.list, jumping
back to the head of the list if needed.
Yes, this is an infinite loop. (Use with caution)
Arguments:
none
Returns:
the next element of self.list
"""
if self.index+1 < self.limit:
self.index+=1
return self.list[self.index-1]
else:
self.index=0
return self.list[self.limit-1]
def __init__(self, inputList):
object.__init__(self)
self.index = 0
self.limit = len(inputList)
self.list = inputList
def next(self):
"""
returns the next element of self.list, jumping
back to the head of the list if needed.
Yes, this is an infinite loop. (Use with caution)
Arguments:
none
Returns:
the next element of self.list
"""
if self.index+1 < self.limit:
self.index+=1
return self.list[self.index-1]
else:
self.index=0
return self.list[self.limit-1]