If statement “无法打印”;否;?
我对Lua非常非常陌生,所以我有点困在学习上了 为什么我不能在这里打印“否”?我还应该补充什么If statement “无法打印”;否;?,if-statement,printing,lua,expression,If Statement,Printing,Lua,Expression,我对Lua非常非常陌生,所以我有点困在学习上了 为什么我不能在这里打印“否”?我还应该补充什么 if (expression_1) then if (expression_2) then print("yes") end else if (expression_3) then print("no") end end expression_1不能为true(nil或false)和expression_3必须为true,才能打印“否”
if (expression_1) then
if (expression_2) then
print("yes")
end
else
if (expression_3) then
print("no")
end
end
expression_1
不能为true
(nil
或false
)和expression_3
必须为true
,才能打印“否”
如果这是您的全部代码,则不会打印“否”,因为expression_3
是nil
,因为您尚未分配任何值
以下代码将打印“否”:
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语句不需要括号。这是无效的Lua代码:需要在底部添加
end
。好的,但它仍然不起作用。“表达式1”和“表达式2”是否必须为真才能打印“否”?您需要提供更多详细信息。可能是实际代码。