Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

what is the reserved keyword "break" in Lua responsible for? What is it for ?

Asked by 4 years ago

I'm researching Lua in Roblox and came across this word. Please explain what she is responsible for?

1
I will advise you to do more research than to be asking in this site. JesseSong 3916 — 4y
0
I'm just still the new guy. and I didn't find it on the roblox site. rewsautaster11 9 — 4y

1 answer

Log in to vote
3
Answered by 4 years ago

so if you're running a loop and there's the word "break" inside, it means that you wanna stop the loop:

for i = 1, 10 do -- this is a loop
    print(i) -- printing the number which "i" is at, in the output
    if i == 5 then -- if i is equal to 5,
        break -- this will stop the loop
    end
end

try it, and watch carefully in the output. To open the output, click "View" on the tab up on the screen, try to find "Output" and click it. Did you see, it printed the numbers all the way to 5, and not to 10, because when it arrived at 5, we broke the loop with the word "break".

Hope this helped!

For more info, check here https://developer.roblox.com/en-us/articles/Loops

2
Extension to this answer: The break keyword only breaks the current thread loop. This means that if you have a for loop inside a while loop and you break the for loop, the while loop will keep going. DeceptiveCaster 3761 — 4y
0
yes i forgot to write that, thx TheRealPotatoChips 793 — 4y
0
cuz i couldn't edit my answer smh TheRealPotatoChips 793 — 4y
Ad

Answer this question