Decreasing for loops in Python impossible?
This is very late, but I just wanted to add that there is a more elegant way: using reversed
for i in reversed(range(10)):
print i
gives:
4
3
2
1
0
for n in range(6,0,-1):
print n
# prints [6, 5, 4, 3, 2, 1]
for n in range(6,0,-1)
This would give you 6,5,4,3,2,1
As for
for n in reversed(range(0,6))
would give you 5,4,3,2,1,0