Appendix C. Order of Operations

When mathematical calculations are performed in a program, each operation takes place according to a prespecified order. This order of operations ensures that the code is run the same way every time. This is no different from arithmetic or algebra, but programming has other operators that are less familiar.

In the following table, the operators on the top are evaluated before the operators later in the list—e.g., multiplication will be evaluated before addition.

Name Symbol Examples

Parentheses

()

a * (b + c)

Unary negation

-

-x

Multiplicative

* / %

a * b

Additive

+ −

a + b

Comparisons

> < <= >= == != in

if a > b

Logical NOT

not

if not mousePressed

Logical AND

and

if mousePressed and (a > b)

Logical OR

or

if mousePressed or(a > b)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.43