Lua 运算符相关

--[[

  运算符
  1. 算数运算符
  +  -  *  /  %  ^幂

  2. 关系云算法
  ==  >=  <=  ~=不等于

  3. 逻辑运算符
  and 与   等于 &&   都为true
  or  或   等于 ||   有一个为true,则true
  not 非   等于 !   a为true,not a 则取反 为 false

--]]

算数运算符:

x,y = 2,4
s = x+y
print(s)
s = x-y
print(s)
s = x*y
print(s)
s = x/y
print(s)
s = x%y
print(s)
s = x^y
print(s)

关系运算符

x,y = 2,4
if(x ~= y) then
print("不等於")
end

逻辑运算符

x,y = 2,false

if( x and y) then
print("与")
else
print("与X")
end

if( x or y) then
print("或")
else
print("与")
end

if( not y) then
print("非")
end

if( x and (not y)) then
print("与")
else
print("与X")
end

or 相当于条件表达式

x,y = 2,false
z = x or {}
print(z)  --输出 2

x = nil
z = x
print(z)  --输出 nil

z = x or {}
print(z)  --输出 table: 002FB788
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值