Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Programming Gambas from Zip/OperatorPrecedence

From Wikibooks, open books for an open world
<Programming Gambas from Zip

Operator Precedence

[edit |edit source]

In an expression, which part gets worked out first, then which operations are worked out next?

For example, is 2 + 3 * 4 equal to 20 (+ first, * second) or is it 14 (* first, then +)? Multiplication precedes addition, so the expression comes down to14.

Rules:

  1. Things are worked out before they are compared.
  2. Anything in brackets is worked out first.
  3. The highest priority is changing the sign (–) or reversing true/false with NOT.
  4. Strings are joined before paths are assembled. (& is done before &/).
  5. Powers are done beforemultiplication or division, which are done beforeaddition or subtraction.
  6. Where there are several operations and they all have the same precedence, the order is left to right but it does not matter because 3 * (4 / 2) is the same as (3 * 4) / 2
  7. Comparisons are worked out before they areANDed,ORed orXORed with other comparisons.

Examples:

4 ^ 2 * 3 ^ 3is the same as (4 ^ 2) * ( 3 ^ 3 )

a > 10 AND a < 20is the same as ( a > 10 ) AND ( a < 20 )

4 * 2 + 3 * 3is the same as ( 4 * 2 ) + ( 3 * 3 )

4 + 2 = 5 + 1is the same as ( 4 + 2 ) = ( 5 + 1 )

Programming Gambas from Zip
 ← FormattingOperatorPrecedenceAfterword → 
Retrieved from "https://en.wikibooks.org/w/index.php?title=Programming_Gambas_from_Zip/OperatorPrecedence&oldid=3562944"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp