首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >if、else、else if和end Lua

if、else、else if和end Lua
EN

Stack Overflow用户
提问于 2012-05-02 14:23:27
回答 1查看 50.8K关注 0票数 29

你知道Lua为什么这么做是错的吗?

代码语言:javascript
复制
       if Pieza == 1 then
            if Rotacion == 1 then
                Piezas = Cuadrado1
            else if Rotacion == 2 then
                Piezas = Cuadrado2
            else if Rotacion == 3 then --this is Line 273
                Piezas = Cuadrado3
            else if Rotacion == 4 then
                Piezas = Cuadrado4
            else
                io.write("Me Envio una rotacion que no existe? \n");
            end 
--this end closes the if inside the first if the one using to compare Rotacion
        else if Pieza == 2 then
            if Rotacion == 1 then
                Piezas = I1
            else if Rotacion == 2 then
                Piezas = I2
            else if Rotacion == 3 then
                Piezas = I3
            else if Rotacion == 4 then
                Piezas = I4
            else
                io.write("Me Envio una rotacion que no existe? \n");
            end
--this end closes the if inside the first if the one using to compare Rotacion
        else  --this else is in case Pieza != 1 || 2
            io.write("Me Envio una pieza que no existe? \n");
        end --this close the whole if (the one comparing "Pieza")

我得到的错误是这个'end‘预期(在第273行关闭'if’)靠近'else‘

此外,在每个if之后添加end (这不是应该做的,但无论如何都要尝试)是不起作用的……

如果你需要我翻译成英语,我会很乐意做的,评论和一切,但我认为这不是必要的这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-02 14:32:37

这是elseif,不是else if (注意空格)。错误是因为解释器希望每个else块都有一个end

有关详细信息,请参阅the manual

票数 54
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10408704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档