Microsoft KB Archive/45907

= QuickBasic's Hierarchy of Operations =

Article ID: 45907

Article Last Modified on 11/21/2006



This article was previously published under Q45907



SUMMARY
The following information on &quot;Hierarchy of Operations&quot; was taken from Pages 45-46 of the &quot;Microsoft QuickBasic 4.0: Basic Language Reference&quot; manual for Versions 4.00 and 4.00b. This information also applies to the following products:


 * 1) Microsoft GW-Basic Versions 3.20, 3.22, and 3.23
 * 2) QuickBasic Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50
 * 3) Microsoft Basic Compiler Versions 5.35, 5.36, 6.00, and 6.00b
 * 4) Microsoft Basic PDS Version 7.00.



MORE INFORMATION
The Basic operators have an order of precedence, that is, when several operations take place within the same program statement (without being grouped by parentheses), some operations are executed before others. Operations are executed in the following order:

 Arithmetic operations

 Exponential (^) Negation (-) Multiplication and division (*, /) Integer division (\) Modula arithmetic (MOD) Addition and subtraction (+, -)</li></ol> </li> Relational operations (=, >, <, <>, <=, >=)</li> Logical operations

<ol style="list-style-type: lower-alpha;"> NOT</li> AND</li> OR</li> XOR</li> EQV</li> IMP</li></ol> </li></ol>

An exception to the order of operations listed above occurs when an expression has adjacent exponentiation and negation operators. In this case, the negation is done first. For example, the following statement prints the value .0625 (equivalent to 4^-2), not -16 (equivalent to -(4^2)):

PRINT 4 ^ -2

If operators on the same precedence level appear in the same expression, they are computed from left to right.

For more information on the &quot;Hierarchy of Operations,&quot; consult the Basic language reference manual for your version of Basic.

Additional query words: QuickBas BasicCom

Keywords: KB45907

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.