官术网_书友最值得收藏!

Operator precedence

Much like math, Lua has the concept of operator precedence. In math, 5 + 2 * 10 equals 25 because multiplication happens before addition. Lua behaves the same way; it even uses parentheses to prioritize one group of equations before another. To see this in action, try running the following code snippet:

print ( 5 + 2 * 10 ) -- prints 25
print ( (5 + 2) * 10 ) -- prints 70

Take note of how the output is different; this is because Lua follows mathematical precedence for arithmetic operators. Order of precedence is listed in this table from higher priority (first row) to lower priority (last row):

主站蜘蛛池模板: 泌阳县| 望谟县| 噶尔县| 靖宇县| 都江堰市| 卓资县| 赣榆县| 内乡县| 益阳市| 临潭县| 灵石县| 龙井市| 炉霍县| 淮滨县| 钟祥市| 苍山县| 宿松县| 大同市| 和平县| 乡城县| 习水县| 清远市| 莱州市| 翁牛特旗| 高邑县| 永春县| 葫芦岛市| 海兴县| 南靖县| 柏乡县| 宕昌县| 荥经县| 乌兰察布市| 崇仁县| 黄龙县| 颍上县| 南部县| 宁晋县| 岳阳市| 黄骅市| 闽清县|