Lua中的逻辑运算符使用详解
程序员文章站
2022-06-24 11:52:01
下表列出了所有的lua语言支持的逻辑运算符。假设变量a持有true,而变量b持有false:
示例
试试下面的例子就明白了所有的lua编程语言提供的...
下表列出了所有的lua语言支持的逻辑运算符。假设变量a持有true,而变量b持有false:
示例
试试下面的例子就明白了所有的lua编程语言提供的逻辑运算符:
复制代码 代码如下:
a = 5
b = 20
b = 20
if ( a and b )
then
print("line 1 - condition is true" )
end
if ( a or b )
then
print("line 2 - condition is true" )
end
--lets change the value ofa and b
a = 0
b = 10
if ( a and b )
then
print("line 3 - condition is true" )
else
print("line 3 - condition is not true" )
end
if ( not( a and b) )
then
print("line 4 - condition is true" )
else
print("line 3 - condition is not true" )
end
当建立并执行上面的程序它会产生以下结果:
复制代码 代码如下:
line 1 - condition is true
line 2 - condition is true
line 3 - condition is true
line 3 - condition is not true
line 2 - condition is true
line 3 - condition is true
line 3 - condition is not true
下一篇: Lua教程(十九):C调用Lua