NWN2 Scripting.




Simulation Training.

Introduction
Home
First Program
Seeing Results
Variables and Data Types
Comments
Functions
Data Conversion
Random Numbers
Concatenation
Arithmetic Operators
Compound Assignments
One More or Less
Precedence
Relational Operators
The Open Branch
The Closed Branch
Logical AND
Logical OR
Compound Statements
ELSE If
Switch Case
The ? Operator
The for Loop
The while Loop
The do while Loop
Introduction to Functions
Passing Values
Passing Multiple Values
Multiple Functions
Simplifying Functions
TRUE/fALSE Conditions
Return Values
Setting Global Variables
Getting Global Variables
Setting Local Variables
Getting Local Variables
WayPoints Introduction
Static Waypoint Sets
Dynamic Waypoint Sets
Dynamic WP Cycles
Input Output

Precedence

Precedence of operations is simply the order in which arithmetic operations are performed.


 

Examples

The following examples illustrate precedence of operations:

 

X = 6 + 12/6 * 2 - 1 Original Problem

Solution:

X = 6 + 2 * 2 - 1 (Division precedence)

X = 6 + 4 - 1 (Multiplication precedence)

X = 9 (Operations from left to right)

 

A = (6 +12)/6 * 2 - 1 Original Problem

Solution:

X = 18/6 * 2 - 1 (Work inside parentheses done first)

X = 3 * 2 - 1 (Operations from left to right)

x = 6 - 1 (Multiplication precedence)

X = 8

 

Y = 6 +12/6 * (2-1) Original Problem

Solution:

Y = 6 + 12/6 * 1 (Work inside parentheses done first)

Y = 6 + 2 * 1 (Operations from let to right)

Y = 6 + 2 (Multiplication Precedence)

Y = 8

 

Z = 6 + 12(6 * 2) - 1 Original Problem

Solution:

Z = 6 + 12/12 - 1 (Work inside parentheses done first)

Z = 6 + 1 - 1 (Division Precedence)

Z = 6 (Operations from left to right)

 


 

Priority Operation
First  ()
Second Negation (assigning a negative number)
Post-Third   * / Multiplication and Division
Fourth   + - Addition and Subtraction 

 

C++ uses the same precedence of operations as illustrated here.

 

 

Nwn2Scripting provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 2008 by Adamson House, Ltd. All Rights Reserved.

Questions or Comments: EMail Webmaster

Donations are to Adamson House, Ltd who maintains this site.
All donations go the the improvement of this site.