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

  • Lua Quick Start Guide
  • Gabor Szauer
  • 110字
  • 2021-08-05 10:30:41

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

主站蜘蛛池模板: 白水县| 通江县| 张家口市| 城口县| 芒康县| 彭阳县| 黄平县| 宝兴县| 昭平县| 梁山县| 绥棱县| 奈曼旗| 绥德县| 绩溪县| 新竹县| 筠连县| 尖扎县| 吉隆县| 洛川县| 枣强县| 淳安县| 元朗区| 临沭县| 浦北县| 旅游| 鲁山县| 雷州市| 宝兴县| 文山县| 和平区| 葫芦岛市| 乌兰浩特市| 昭通市| 邹平县| 永兴县| 平原县| 广灵县| 海兴县| 桃园县| 枝江市| 东乡县|