Freelance Writing Jobs | Today's Articles | Sign In

 
Browse Sections

Operator Precedence


For example, suppose you have the statement

x = 6 * 5 / 2 - 5 + 11 

In normal circumstances, the variable x would be evaluated in the following order:

6*5=30
30/2=15
15-5=10
10+11=21
x=21 'Final value of X

If you want to express 5+11 the first, just surround them with parentheses:

x = 6 * 5 / 2 - ( 5 + 11 )

which would result in the following order:

5+11=16
6*5=30
30/2=15
15-16=-1
x=-1 'Final value of X 

The difference in results is due to the parentheses around part of the expression, which can have a dramatic impact on the results.

The copyright of the article Operator Precedence in VB Script is owned by Maxim Karetnikov. Permission to republish Operator Precedence in print or online must be granted by the author in writing.

Go To Page: 1 2

Articles in this Topic    Discussions in this Topic

;