2017-08-01 87 views
-4

我是非常非常新的Lua,所以我有点卡住研究它。无法打印“否”?

为什么我不能在这里打印“否”?我还应该添加什么?

if (expression_1) then 
    if (expression_2) then 
     print("yes") 
    end 
    else 
    if (expression_3) then 
     print("no") 
    end 
    end 
+0

这是无效的Lua代码:你需要在底部添加'end'。 – lhf

+0

好吧,但它仍然无法正常工作。为了打印“否”,“expression_1”和“expression_2”是否必须是真的? – doesjohn04

+1

你需要提供更多细节。可能与实际的代码。 – lhf

回答

2

expression_1切不可truenilfalse)和expression_3必须以打印出 “无” true

如果这是您的整个代码,则不会打印“否”,因为expression_3nil,因为您尚未分配任何值。

下面的代码将打印无:

local expression_3 = true  
if (expression_1) then 
    if (expression_2) then 
    print("yes") 
    end 
else 
    if (expression_3) then 
    print("no") 
    end 
end 

你也可以写

local expression_3 = true  
if expression_1 and expression_2 then 
    print("yes") 
elseif expression_3 then 
    print("no") 
end 

顺便说一句,你不需要括号的if语句。