Say if I have a repeat until loop which repeats 3 times or until the players data loads. In one example I saw someone used return end
if the players data saved successfully. Why do they not just use break
? Hope someone can clarify this for me. Thanks!
Return & break are different things and should never be confused.
Return will stop whatever function that it is. Meaning that if I did:
local function ok() local yes = true if yes == true then return end print("nice") end ok()
print("nice") would never run, since the function had already stopped. It's very, very crucial to note that return's purpose is for returning data back to where it was called, meaning that:
local function ok() return 5 end local x = ok();
x would be equivalent to 5, since the function returned that. So return stops & gives back data if put in.
Break, on the other hand would stop whatever loop it is in, and it does not return any data.
If i did:
for i = 10, 0, -1 do if i == 5 then break end end
The loop would not go farther 4, since it would stop running, or "breaking" at 5