22 posts
Posted 06 December 2012 - 10:21 AM
Is there a way to call for loops, in other words reuse a loop, make the loop do the same thing again?
436 posts
Posted 06 December 2012 - 10:25 AM
… If you mean making multiple of the same loop, then yes, just close it in another loop.
for x =1 , 2 do
for y = 10, 15 do
term.setCursorPos(x,y)
term.write("*")
end
end
And you can nest them pretty much forever, but I would be wary of doing that.
514 posts
Location
Over there
Posted 06 December 2012 - 10:28 AM
Are you talking about calling a loop from anywhere in your code?
In that case, you should look up how to use functions.
231 posts
Posted 06 December 2012 - 10:46 AM
If you want to reuse a loop, you can just enclose it in a function:
function loop()
for 1, 7 do
-- Do stuff here
end
end
Then you can call it from anywhere in your code (after you create the function).
252 posts
Posted 07 December 2012 - 03:16 PM
You could probably do something like this too, if you wanted: (With a while loop)
while UseLoop do
-- What you want to be repeated while UseLoop is true...
end
How you would use this loop?
UseLoop = true -- Enables loop
-- And
UseLoop = false -- Disables loop
2217 posts
Location
3232235883
Posted 07 December 2012 - 04:01 PM
or even:
while true do
if something then
break -- jump to the inner most loop's end
end
end
22 posts
Posted 09 December 2012 - 02:36 AM
If you want to reuse a loop, you can just enclose it in a function:
function loop()
for 1, 7 do
-- Do stuff here
end
end
Then you can call it from anywhere in your code (after you create the function).
OK, thank you, I was wondering if you could do that :)/>