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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

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

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

reverse of for loop

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] bio
Date Fri 15 Jul 2011 02:40 PM (UTC)  quote  ]
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  (848 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Fri 15 Jul 2011 06:48 PM (UTC)  quote  ]

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

http://aardwolfclientpackage.googlecode.com/
[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)  quote  ]
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.


868 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]