﻿ NewBie's Corner Session 5 Operator Precedence | InterSystems Developer
Article
· May 26, 2016 2m read

# 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.

If you have a comment, please respond through the InterSystems Developer Community, don't send me private email. Unless of course you wish to address me only.

See NewBie Index for an index of all NewBie Corner posts.

There is no reason for any individual to have a computer in his home.

Software comes from heaven when you have good hardware.

The nicest thing about standards is that there are so many of them to choose from.

Ken Olsen, founder and CEO of Digital Equipment Corporation, 1977

Discussion (0)0