下表列出了所有的Lua語言支持的算術(shù)運(yùn)算符。假設(shè)變量A持有10和變量B持有20,則:
![](http://img.jbzj.com/file_images/article/201505/2015527120458107.jpg?20154271259)
例子
試試下面的例子就明白了所有的Lua編程語言提供了算術(shù)運(yùn)算符:
復(fù)制代碼 代碼如下:
a = 21
b = 10
c = a + b
print("Line 1 - Value of c is ", c )
c = a - b
print("Line 2 - Value of c is ", c )
c = a * b
print("Line 3 - Value of c is ", c )
c = a / b
print("Line 4 - Value of c is ", c )
c = a % b
print("Line 5 - Value of c is ", c )
c = a^2
print("Line 6 - Value of c is ", c )
c = -a
print("Line 7 - Value of c is ", c )
當(dāng)執(zhí)行上面的程序,它會(huì)產(chǎn)生以下結(jié)果:
復(fù)制代碼 代碼如下:
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2.1
Line 5 - Value of c is 1
Line 6 - Value of c is 441
Line 7 - Value of c is -21
您可能感興趣的文章:- Lua中..和#運(yùn)算符的使用方法
- Lua中的邏輯運(yùn)算符使用詳解
- Lua中關(guān)系運(yùn)算符的使用教程
- Lua中的運(yùn)算符簡明總結(jié)
- Lua學(xué)習(xí)筆記之運(yùn)算符和表達(dá)式
- Lua基礎(chǔ)之運(yùn)算符的使用示例