LogicMachine Forum
Reverse for i loop - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Reverse for i loop (/showthread.php?tid=4399)



Reverse for i loop - sx3 - 25.11.2022

Hello,

I'm trying to figure out a way to reverse a loop counting backwards instead.
This code work for normal loop

Code:
local strStart = 1 local strStop = 5 local result = 0 for i = strStart, strStop do   result = result + 1   log(result, i) end

But running something like this, renders nothing.
Code:
local strStart = 5 local strStop = 1 local result = 5 for i = strStart, strStop do   result = result - 1   log(result, i) end

Is it possible to do a reverse loop with simple code?


RE: Reverse for i loop - admin - 25.11.2022

Use this:
Code:
for i = 5, 1, -1 do ... end