Order of evaluation for operations

The values involved in an operation must be of the same data type. Operations occur in the following order:

  • Parenthesis -- You can explicitly force the order of evaluation with parentheses. Operations within parentheses occur first. For example:
    (5 - 3) * (6 - 4) = 4
  • Precedence -- Operations not in parentheses occur in order of precedence starting with precedence 1. For example, multiplication has greater precedence than subtraction so 3 * 6 occurs first:
    5 - 3 * 6 - 4 = -17 
  • Left to right -- Operations of equal precedence occur left to right. For example:
    8 / 4 * 2 = 4