Safe to Return from Repeat-Until?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Safe to Return from Repeat-Until?

Post 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?
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Safe to Return from Repeat-Until?

Post 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
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Safe to Return from Repeat-Until?

Post by Bugala »

thanks for confirming.
Post Reply