Lua 中 elseif 和 else if 有何区别?

Lua 中的 elseif 和 else 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

点赞
用户2858170
用户2858170

Lua 中没有 else if

正确的语法是 elseif

让我们修正一下缩进:

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

这只是有点更复杂。这只有在需要更多的 else 块时才有意义。 如果对于所有的条件只有一个 else 块,那么 elseif 就足够了。

2019-03-11 16:46:31