Possible Duplicate:
Is there a reason that we cannot iterate on “reverse Range” in ruby?
This works like magic.
for i in 1..10
...
end
Isn’t it only intuitive that this backward for loop should work as well?
for i in 10..1
...
end
If there is some syntactical reason why this shouldn’t work, I feel like ruby has to be changed to allow it. It’s just intuitive to write backward for loop that way.
1..10is of class Range, not directly linked with any loop constructs. And there are no numbers that are both bigger than 10 and smaller than 1, therefore the range10..1is empty.PS I don’t recall when was the last time I wrote a for loop in ruby. Maybe something from http://www.ruby-doc.org/core-1.9.2/Enumerable.html would serve you better?