Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement “无法打印”;否;?_If Statement_Printing_Lua_Expression - Fatal编程技术网

If statement “无法打印”;否;?

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,才能打印“否”

我对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
,才能打印“否”

如果这是您的全部代码,则不会打印“否”,因为
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”是否必须为真才能打印“否”?您需要提供更多详细信息。可能是实际代码。