I am fairly new to scripting, and wondering, what would the function elseif
do? and how would I properly execute it? I know what else
does, and can't figure out how to use elseif
.
First of all, elseif
is not a function. It is a keyword.
The difference between elseif
and else
is that the former lets you specify a new condition which must be true for the block to be entered, while the latter executes if and only if all previous if
and elseif
s failed.
It is really just a combination of else
and if
:
if A then -- do something if `A` is true elseif B then -- do something else if `A` is false but `B` is true end
is equivalent to
if A then -- do something if `A` is true else if B then -- do something else if `A` is false but `B` is true end end
The former is clearer and should be preferred.