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

Are there any alternatives to elseif?

Asked by 3 years ago

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?

0
maybe you could use dictionaries Leamir 3138 — 3y

1 answer

Log in to vote
1
Answered by
iOwn_You 543 Moderation Voter
3 years ago

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.

Ad

Answer this question