如果在Lua中,elseif和else之间的区别是什么?

问题描述 投票:1回答:1

Lua的elseifelse if有什么区别?我不知道它们是否相同而是更短。

x= 100
y= 100

if x > 90 then
  ...
else if y > 110 then
  ...
else
  ...
end
end

if x > 90 then
  ...
elseif y > 110 then
  ...
else
  ...
end




lua
1个回答
1
投票

Lua没有else if

正确的语法是elseif

让我们来解决你的问题:

if x > 90 then
  ...
else
  if y > 110 then
    ...
  else
    ...
  end
end

这有点复杂。这只有在你需要更多其他块的情况下才有意义。如果所有条件只有一个其他块,那么elseif就足够了。

© www.soinside.com 2019 - 2024. All rights reserved.