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

Are there any alternatives to elseif?

So I have this code...

if a then
	--1
elseif b then
	--2
elseif c then
	--3
elseif d then
	--4
end

is there a way I could rewrite this to make it look more neat?

1 comment

0

maybe you could use dictionaries

1 answer

It depends on what youre planning to do inside the it statements.

Sometimes using a dictionary / array could benefit you here but in most cases no, there is no alternative to using elseif, keep in mind you also have some logic expressions you can use:

if condition1 and condition2 then
-- will execute if both of the conditions are met
end

if condition1 or condition2 then
 -- will execute when condition1 OR condition2 are met
end

if not condition then
-- will execute if the condition is not met
end

The OR logical expression could also sometimes be a substitute for an elseif.

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