Page 1 of 1

Safe to Return from Repeat-Until?

Posted: Thu Sep 04, 2025 1:12 pm
by Bugala
Never thought this before, and I suppose this is safe, but checking just in case.

Suppose:

Code: Select all

Function Func()
   Repeat
       Return
   Until A=1
EndFunction
It is safe to use RETURN to get out of Repeat-Until loop, that doesnt mean that I would somehow end up back to this Repeat-Until loop, which I interrupted by using Return, but instead also the Repeat-Until loop gets cancelled when returning in middle of it?

Re: Safe to Return from Repeat-Until?

Posted: Fri Sep 05, 2025 7:57 am
by jPV
Yes, it's safe. Return finishes the function call and never returns to it. Maybe it would be better for code readability to have Return at the end of the function and exit from the loop with Break, but it shouldn't do any harm to do otherwise either.

Here's what Lua documentation tells: https://www.lua.org/pil/4.4.html

Re: Safe to Return from Repeat-Until?

Posted: Sat Sep 06, 2025 9:23 am
by Bugala
thanks for confirming.