下表列出了所有的Lua語言支持的算術運算符。假設變量A持有10和變量B持有20,則:

例子
試試下面的例子就明白了所有的Lua編程語言提供了算術運算符:
復制代碼 代碼如下:
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 )
當執行上面的程序,它會產生以下結果:
復制代碼 代碼如下:
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中..和#運算符的使用方法
- Lua中的邏輯運算符使用詳解
- Lua中關系運算符的使用教程
- Lua中的運算符簡明總結
- Lua學習筆記之運算符和表達式
- Lua基礎之運算符的使用示例