I keep seeing people use elseif’s and I just normally use if’s, What’s the difference between them and how do elseif’s work?
( I looked on the Roblox API Reference for this and didn’t understand what Roblox was trying to get at on their so… )
I keep seeing people use elseif’s and I just normally use if’s, What’s the difference between them and how do elseif’s work?
( I looked on the Roblox API Reference for this and didn’t understand what Roblox was trying to get at on their so… )
Elseifs run if the first if isn’t true. For example.
if 1 == 2 then --false
print("1 equals 2!")
elseif 1 == 1 then --true
print("1 equals 1!")
else --neither of them are true
print("Math is broken?")
end
In this scenario, it will print “1 equals 1!”, and you can add as many elseifs as you want.
if 1 was == to nil then, would it print(“Math is broken?”)?
The API reference does a good job explaining it in simple terms so I’m not sure what exactly you want to know.
The difference is in their purpose. You can use if statements to evaluate several conditions for the same thing (e.g comparisons against a static value) separately, or if you want to speed up your code and improve on legibility and provided they can be used for the purpose, you can incorporate the use of else or elseif statements to execute a block of code only if the preceding expressions evaluated to false.
Yes, because 1 == nil is false.