reverse of for loop

Posted by Tkl1129 on Fri 15 Jul 2011 02:40 PM — 3 posts, 13,881 views.

Hong Kong #0
I have question for "for" function.
Numberic For can

for i = 2,5 do
   print(i) -- This return 2 ..3..4..5
end --for


But I want to make a reverse


for i = 5,2 do
   print(i) -- Hope display 5..4..3..2..but fail
end --for


do there any method to achieve this?
or only do a stupid thing like


local loop1 = 5 - 2 + 1
local loop2 = 5
   for i = 1,loop1 do
   print(loop2)
   loop2 = loop2 - 1 -- display 5..4..3..2
end-for


Any other method?
Thanks~
USA Global Moderator #1
for i=5,2,-1

the for loop has a 3rd parameter implicitly set to 1 if not used for how much to step by
Amended on Fri 15 Jul 2011 06:50 PM by Fiendish
Hong Kong #2
ah..--__--"

yes...How stupid I am !!!..

Thanks~