這篇文章主要介紹了Lua中的邏輯運算符使用詳解,是Lua入門學習中的基礎知識,需要的朋友可以參考下
下表列出了所有的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