lua中的運算子與if語句
阿新 • • 發佈:2019-02-09
--lua中的運算子 加+ 減- 乘* 除/ a=3+5 b=3-1 c=11-2*2 d=1+9/3 print(a,b,c,d) --關係運算符 大於> 小於< 等於== 不等於~= 大於等於>= 小於等於<= --結果是布林值 a=22 b=212 print(a,">",b,"=",a>b) print(a,"<",b,"=",a<b) print(a,"==",b,"=",a==b) print(a,"~=",b,"=",a~=b) --在c語言 != print(a,">=",b,"=",a>=b) print(a,"<=",b,"=",a<=b) --編輯運算子 and or not print(a and b) --and與同c語言中的&& 這個是進行位的相加運算 print(a or b) --and與同c語言中的|| print("not a",not a) --not與同c語言中的! --控制結構 if --[[ 方式一 if then end 方式二 if then else end 方式三 if then elseif then elseif then elseif then else end --]] if a>b then print(a,">",b) a=33 b=1 if a>b then print(a,">",b) end 進行&運算1 1得1 00010110 11010100 00010100 --lua中的運算子 加+ 減- 乘* 除/ a=3+5 b=3-1 c=11-2*2 d=1+9/3 print(a,b,c,d) --關係運算符 大於> 小於< 等於== 不等於~= 大於等於>= 小於等於<= --結果是布林值 a=22 b=212 print(a,">",b,"=",a>b) print(a,"<",b,"=",a<b) print(a,"==",b,"=",a==b) print(a,"~=",b,"=",a~=b) --在c語言 != print(a,">=",b,"=",a>=b) print(a,"<=",b,"=",a<=b) --編輯運算子 and or not print(a and b) --and與同c語言中的&& 與運算 print(a or b) --and與同c語言中的|| 或運算 print("not a",not a) --not與同c語言中的! a=55 b=44 if a>b then print(a,">",b) else print(a,"<",b) end if a~=b then print(a,"不等於",b) elseif a>b then print(a,">",b) elseif a<b then print(a,"<",b) else print(a,"==",b) end