用户登录
用户注册

分享至

Lua中的逻辑运算符使用详解

  • 作者: 殷楷博
  • 来源: 51数据库
  • 2021-08-21

下表列出了所有的lua语言支持的逻辑运算符。假设变量a持有true,而变量b持有false:

 示例

试试下面的例子就明白了所有的lua编程语言提供的逻辑运算符:

复制代码 代码如下:
a = 5
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

软件
前端设计
程序设计
Java相关