Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-3

More than 1 "If"?

Asked by 9 years ago

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

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'. TheeDeathCaster 2368 — 9y

2 answers

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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
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. BlueTaslem 18071 — 9y
0
This is truth, but it's impossible to know which is better without a situation to apply it to. adark 5487 — 9y
0
I have a feeling he might've been asking about nested if statements. DigitalVeer 1473 — 9y
Ad
Log in to vote
-2
Answered by 9 years ago

Example

local value1 = 0
if value1 == 1 then
print("1")
else
if value1 == 0 then
print("0")
    end
end
0
It would need to be else (skip a line then) if DevScripting 92 — 9y
0
You cant have more then 1 elseif statements only 1 DevScripting 92 — 9y
2
You can use more than 1 'elseif' statement. TheeDeathCaster 2368 — 9y
0
You almost never use it though @TheAlphaStigma DevScripting 92 — 9y
View all comments (2 more)
2
There are *many* cases where that is false, DevScripting. Why would you avoid useing `elseif` anyway? It's a lot easier to type. adark 5487 — 9y
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 TheeDeathCaster 2368 — 9y

Answer this question