Here's an example that cycles through 3 number, 0, 1, and 2:
### >>> j=0 >>> for i in range(10): .. print j .. j = (j+1)%3 .. 0 1 2 0 1 2 0 1 2 0 ###
A nice way to do this is with itertools.cycle(): >>> import itertools >>> cyc = itertools.cycle(range(3)) >>> for i in range(10): ... print cyc.next() ... 0 1 2 0 1 2 0 1 2 0
Kent
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor