lua语言的if判断语句

lua语言的判断比较迷,0被视为真

a=0
b=(a==0)
c=(a==1)
d=1
print(a)
print(b)
print(c)
if(b)
    then 
    print("a==0 means true")
    end
if(b==1)
      then 
    print("true means 1")
    else
    print("true do not mean 1")
    end
if(c==0)
    then
    print("false means 0")
    else
    print("c is false, but not means 0")
    end
if(c==1)
    then 
    print("false means 1")
    else
    print("c is flase, but not means 1")
    end
if(1)
    then 
    print("1 means true")
    end
if(0)
    then 
    print("0 means true")
    end

运行结果

0
true
false
a==0 means true
true do not mean 1
c is false, but not means 0
c is flase, but not means 1
1 means true
0 means true

猜你喜欢

转载自blog.csdn.net/sinat_39416814/article/details/104560607