Skip to main content

Order of Operations

The order of operations is a rule that tells the correct sequence of steps for evaluating expressions. It is the difference between 5 + 2 * 3 being evaluated as (5 + 2) * 3 instead of 5 * (2 + 3).

Comparison Operators#

Comparison operators compare two expressions with each other, returning a boolean (true/false) value. However, the two expressions have to evaluate to a number or else it will error. For example 5 < 6.5 is valid and would return true, but 5 < "hello" is invalid because the second type is not a number.

Expression#

An expression is a block of code that evaluates/outputs a value. For example 5 + 2 * 3 is an expression because it returns 11. There are other types of expressions in LemonScript, for example functions and statements, but here, we are going to focus on arithmetic expressions. Arithmetic expressions are evaluated in LemonScript in the same way as in mathematics. You may have heard of PEMDAS or BODMAS. LemonScript follows it. If there's variables in the expression, they will be evaluated first.

  • 5 + 5 * 3 = 5 + (5 * 3) = 20
  • 2 ^ (5 + 3) = 2 ^ 8 = 256
  • 8 + 7 % 6 / 3 = 8 + ((7 % 6) / 3) = 8 + (1 / 3) = 8.33