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

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):

主站蜘蛛池模板: 镇康县| 临邑县| 阜城县| 连山| 泗洪县| 忻州市| 合水县| 桂阳县| 临朐县| 开化县| 台江县| 普陀区| 梁河县| 仪征市| 扎兰屯市| 淮滨县| 安阳县| 清涧县| 哈尔滨市| 靖远县| 郓城县| 凤庆县| 会理县| 娄烦县| 新巴尔虎左旗| 柞水县| 琼中| 项城市| 万载县| 崇仁县| 绍兴县| 衡水市| 繁峙县| 个旧市| 罗甸县| 巴青县| 资兴市| 黄石市| 建德市| 长白| 曲麻莱县|