﻿ NewBie's Corner Session 5 Operator Precedence | InterSystems Developer

# NewBie's Corner Session 5 Operator Precedence

NewBie's Corner Session: 5 Operator Precedence

Welcome to NewBie's Corner, a weekly or biweekly post covering basic Caché Material.

Click on the Caché Cube in your system tray and select Terminal to try out the commands.

Order Precedence means the order in which mathematical operators are executed. In a Mathematical expression, you may have Multiplication, Addition, Subtraction, and Division. Which of these are executed first, second, third, etc.?

The basic Operator Precedence of mathematics is:

Multiplication and Division has precedence over Addition and Subtraction

In normal mathematics when you encounter an expression like 5+7*10, the multiplication and division is executed first, and then addition and subtraction, so 5+7*10 is 75 (7*10=70+5=75).

However, in Caché the Operator Precedence is strictly left to right,

So:  5+7*10=120  (5+7=12*10=120).

###### 16

If you want your expressions interpreted a specific way, you must use parenthesis around the expressions you want evaluated first.  Although this concept seems simple enough, I would dare say there is not a Caché/MUMPs programmer alive that has not been bitten by Operator Precedence, keep an eye on this one.

Until next time.