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

Quick Question about Elseif?

1 answer

✓ Accepted answer

First of all, elseif is not a function. It is a keyword.

The difference between elseif and else is that the former lets you specify a new condition which must be true for the block to be entered, while the latter executes if and only if all previous if and elseifs failed.

It is really just a combination of else and if:

if A then
	-- do something if `A` is true
elseif B then
	-- do something else if `A` is false but `B` is true
end

is equivalent to

if A then
	-- do something if `A` is true
else
	if B then
		-- do something else if `A` is false but `B` is true
	end
end

The former is clearer and should be preferred.

1 comment

0

I'd like to add that an if statement can have as many elseif clauses as you want, but can only have a single else clause located at the very end.

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