Lua 条件上下文
例子
Lua中的条件上下文(if,elseif,while,until)不需要布尔值。像许多语言一样,任何Lua值都可以出现在条件中。评估规则很简单:
false并nil算作假。
其他一切都视为真实。
if1then
print("数字工作。")
end
if0then
print("Even0istrue")
end
if"stringswork"then
print("字符串工作。")
end
if""then
print("即使是空字符串也是如此。")
end
Lua中的条件上下文(if,elseif,while,until)不需要布尔值。像许多语言一样,任何Lua值都可以出现在条件中。评估规则很简单:
false并nil算作假。
其他一切都视为真实。
if1then
print("数字工作。")
end
if0then
print("Even0istrue")
end
if"stringswork"then
print("字符串工作。")
end
if""then
print("即使是空字符串也是如此。")
end