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

More than 1 "If"?

Can You do more than 1 if and elseif? Not really much to my description but can you do that though?

1 comment

0

You can use multiple 'elseif' statements for an 'if' statement, however, you can only use one 'else' for an 'if' statement; The 'else' keyword is kind of like an 'if-all-else-fails-then', the 'elseif' keyword is kind of like 'if-this-doesn't-work-and-another-does-then'.

2 answers

Please attempt to actually try this yourself before asking here:

An if statement is limited to one if and one else, but you can have any number of elseifs:

if COND then
	--code
elseif OTHERCOND then
	--code
elseif THIRDCOND then
	--code
else
	--code
end

--Else and elseif are not necessary:

if COND then
	--code
end

if COND then
	--code
else
	--code
end

if COND then
	--code
elseif OTHERCOND then
	--code
end

3 comments

0

It is good to note that really large if elseif else trees are usually a sign that you should use a dictionary or other explicit formula instead.

0

This is truth, but it's impossible to know which is better without a situation to apply it to.

0

I have a feeling he might've been asking about nested if statements.

Example

local value1 = 0
if value1 == 1 then
print("1")
else
if value1 == 0 then
print("0")
	end
end

6 comments

0

It would need to be else (skip a line then) if

0

You cant have more then 1 elseif statements only 1

2

You can use more than 1 'elseif' statement.

0

You almost never use it though @TheAlphaStigma

2

There are many cases where that is false, DevScripting. Why would you avoid useing elseif anyway? It's a lot easier to type.

0

That is incorrect information; I use it almost all the time in the Scripting Field for some of my experiments, as do other scripters, to me, it is primarily used for 'debugging'. @DevScripting

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