Function loops, what do you think?

Hello, what are your thougs about function loops?
What I mean:

function loop()
print("hi!")
wait(1)
loop()
end
loop()

Is this more efficient than while true do loops?

Probably not. You’ll also run into a stack overflow error at some point, so using a function loop is not a good idea.

1 Like

I didn’t knew it could cause a stack overflow o:
I though it could only happening when indexing and listening to __newindex
like;
image

Lua has a tail-call optimization, but Roblox’s Lua VM does not implement this. So, in Roblox, tail-calling recursive function is not as optimized as it could have been.

function x()
-- Yielding code
	return x()
end

x()

Would normally be an optimized process, but just use a loop if you have a never-ending criteria.

3 Likes