我应该结束每个 elseif 块吗?

Am I supposed to have to end every elseif block?

我对 Lua 中的 elseif 块有点困惑。在 official Lua tutorial thing 上,它表明整个 if 块只需要 1 端。但是,在我的代码中,每当我没有为 if 中的每个 elseif 添加关闭时,我都会收到错误消息。这是我的代码:

  if direction == 1 then
    snakeHead.y = snakeHead.y - 2
  else if direction == 2 then
    snakeHead.x = snakeHead.x + 2
  else if direction == 3 then
    snakeHead.y = snakeHead.y - 2
  else if direction == 4 then
    snakeHead.x = snakeHead.x - 2
  end
  end
  end
  end

此外,此代码在 Love2D 中,尽管这可能与问题完全无关。

如果你仔细阅读你引用的教程,你会发现你需要使用 elseif 而不是 else if。也就是说,它是一个关键字,而不是两个。