Function efficiency

Just wondering, which of these functions would be better or more efficient

this:

[code]-- function with two “ifs”
function event ()

if event.phase == “began” then

if event.target.myId == “button1” then
– do something
end

if event.target.myId == “button2” then
– do something
end

end
end[/code]

or this:

[code]-- function with an “if” and an “elseif”
function event ()

if event.phase == “began” then

if event.target.myId == “button1” then
– do something

elseif event.target.myId == “button2” then
– do something
end

end
end[/code] [import]uid: 116264 topic_id: 25517 reply_id: 325517[/import]

http://www.lua.org/pil/4.3.1.html

It’s better to do the latter.

With the second example you provided it basically equates to this

  
if myVal == "yes" then --first to get executed  
elseif myVal == "no" then --only gets executed if myVal is not equal to yes.  

And even faster is if you are comparing a variable that can only have two values is to use if then else.

Eg:

[code]

if myVal == true then
–do something
else --it is false
–do something
end
[/code] [import]uid: 84637 topic_id: 25517 reply_id: 103195[/import]