[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  reverse of for loop

reverse of for loop

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] bio
Date Fri 15 Jul 2011 02:40 PM (UTC)
Message
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~
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Fri 15 Jul 2011 06:48 PM (UTC)

Amended on Fri 15 Jul 2011 06:50 PM (UTC) by Fiendish

Message
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

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] bio
Date Reply #2 on Sat 16 Jul 2011 12:38 AM (UTC)
Message
ah..--__--"

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

Thanks~
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


9,752 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]