Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

1

I will advise you to do more research than to be asking in this site.

0

I'm just still the new guy. and I didn't find it on the roblox site.

1 answer

✓ Accepted answer

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

3 comments

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.

0

yes i forgot to write that, thx

0

cuz i couldn't edit my answer smh

This discussion is preserved as it was. New answers, comments, and votes are closed.