Is there a way to call for loops, in other words reuse a loop, make the loop do the same thing again?
6 replies to this topic
#1
Posted 06 December 2012 - 10:21 AM
#2
Posted 06 December 2012 - 10:25 AM
... If you mean making multiple of the same loop, then yes, just close it in another loop.
And you can nest them pretty much forever, but I would be wary of doing that.
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.
#3
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.
In that case, you should look up how to use functions.
#4
Posted 06 December 2012 - 10:46 AM
If you want to reuse a loop, you can just enclose it in a function:
Then you can call it from anywhere in your code (after you create the 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).
#5
Posted 07 December 2012 - 03:16 PM
You could probably do something like this too, if you wanted: (With a while loop)
How you would use this 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
#6
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
#7
Posted 09 December 2012 - 02:36 AM
faubiguy, on 06 December 2012 - 10:46 AM, said:
If you want to reuse a loop, you can just enclose it in a function:
Then you can call it from anywhere in your code (after you create the 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
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











