什么';elseif和elseif在Lua中的区别是什么?

什么';elseif和elseif在Lua中的区别是什么?,lua,Lua,Lua中的elseif和else if有什么区别?我不知道它们是不是一样,但是比较短 x=100 y=100 如果x>90,则 ... 否则,如果y>110,则 ... 其他的 ... 结束 结束 如果x>90,则 ... 如果y>110,则 ... 其他的 ... 结束 如果Lua中有,则没有else 正确的语法是elseif 让我们修复您的问题: if x > 90 then ... else if y > 110 then ... else ...

Lua中的
elseif
else if
有什么区别?我不知道它们是不是一样,但是比较短

x=100
y=100
如果x>90,则
...
否则,如果y>110,则
...
其他的
...
结束
结束
如果x>90,则
...
如果y>110,则
...
其他的
...
结束

如果Lua中有,则没有else

正确的语法是
elseif

让我们修复您的问题:

if x > 90 then
  ...
else
  if y > 110 then
    ...
  else
    ...
  end
end
只是有点复杂。这只有在您还需要更多的else块时才有意义。
如果所有条件只有一个else块,那么elseif就足够了。

在Lua中有
else If
,但是每个
If
都需要一个
end
。区别在于您已经知道:如果使用
else If
,那么每个
If
都需要一个
end
。如果您使用
else If
,那么您只需要一个
end
if x > 90 then
  ...
else
  if y > 110 then
    ...
  else
    ...
  end
end