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

Can you use break statement in functions, or just loops?

I am confused.... answers would be greatly appreciated!

1 comment

0

break can only be used in loops only. However, you can use return to end a function

1 answer

✓ Accepted answer

break only works in loops, however, you can end a function by using return.

function loopThroughMeTableForValue(table,value) -- some function
	for i,v in pairs(table) do --loops through the table
		if v == value then --checks if the desired value is found, and if it is
			return i --returns the index of the value, and ends the function right there
		end
	end
	return "Didn't find it"  --if the function made it this far, then it didn't find the requested value
end

You can find more about return here.

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