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?
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?
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.
1 comment
maybe you could use dictionaries