This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cranium's profile picture

Iterate in reverse order through a table.

Started by Cranium, 07 December 2012 - 07:36 AM
Cranium #1
Posted 07 December 2012 - 08:36 AM
I want to use a for loop, but instead of iterating sequentially in ascending order, I would like to go in descending order. So for example,

for i = 5,1 do
	print("descending order #"..i)
end
How would I do that?

EDIT: Extensive googling gave me my answer.


for i = 5,1,-1 do --using iterations of -1
	print("descending order #"..i)
end
Edited on 07 December 2012 - 07:41 AM
Lyqyd #2
Posted 07 December 2012 - 08:42 AM
for var = start, end, step do

Use a negative value for step.
Cranium #3
Posted 07 December 2012 - 09:09 AM
Literally found the solution only seconds before you posted, Lyqyd. But thanks anyway.