|
|||||||||||||||||||||
|
Order of Precedence in Statements Consider the following statement: x = 9 + 4 * 2
In Visual Basic, the default order of precedence is that in a statement with multiplication/division operators and addition/subtraction operators, multiplication/division is performed first, before the addition/subtraction. In the preceding example, the default answer is 17. Other operators, such as comparison, logical, and string, are also affected by precedence. When multiple types of operators are in a single statement, operator precedence controls what's performed first. Math operators are performed first, then comparison operators, and finally logical operators
Parentheses are used to control specifically which parts of a statement are performed first. Without parentheses, operator precedence allows the program to determine what operation to do first. To ensure that arithmetic operations happen in the order you want them to, you can use parentheses to group operations. For example, by using the preceding statement, you could group operations as x = (9 + 4) * 2 `results in 26 or x = 9 + (4 * 2) `results in 17 In the next article, we shall study about strings and their implementations in VB
Go To Page: 1
The copyright of the article Precendence of Operators in Learning Visual Basic is owned by . Permission to republish Precendence of Operators in print or online must be granted by the author in writing.
|
|||||||||||||||||||||
|
|
|||||||||||||||||||||
|
|
|||||||||||||||||||||