Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

An Introduction to Dragon/Lessons/Operators

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Operators In this chapter we will introduce the operators provided by the Dragon programming language. Arithmetic Operators The next table presents all of the arithmetic operators provided by the Dragon language. Assume variable x = 50 and variable y = 10, then: +------------+---------------+----------+---------+ | Operator | Description | Example | Result | +============+===============+==========+=========+ | + | Add | x+y | 60 | +------------+---------------+----------+---------+ | - | Subtract | x-y | 40 | +------------+---------------+----------+---------+ | * | Multiply | x*y | 500 | +------------+---------------+----------+---------+ | / | Divide | x/y | 5 | +------------+---------------+----------+---------+ | % | Modulus | x%y | 0 | +------------+---------------+----------+---------+ | ++ | Increment | x++ | 51 | +------------+---------------+----------+---------+ | -- | Decrement | x-- | 49 | +------------+---------------+----------+---------+ Relational Operators The next table presents all of the relational operators provided by the Dragon language. Assume variable x = 50 and variable y = 10, then: +------------+---------------------+-------------+---------+ | Operator | Description | Example | Result | +============+=====================+=============+=========+ | == | Equal | x == y | False | +------------+---------------------+-------------+---------+ | != | Not Equal | x != y | True | +------------+---------------------+-------------+---------+ | > | Greater than | x > y | True | +------------+---------------------+-------------+---------+ | < | Less than | x < y | False | +------------+---------------------+-------------+---------+ | >= | Greater or Equal | x >= y | True | +------------+---------------------+-------------+---------+ | <= | Less than or Equal | x <= y | False | +------------+---------------------+-------------+---------+ Logical Operators The next table presents all of the logical operators provided by the Dragon language. Assume variable x = true and variable y = false, then: +------------+---------------------+-------------+---------+ | Operator | Description | Example | Result | +============+=====================+=============+=========+ | && | Logical AND | x && y | false | +------------+---------------------+-------------+---------+ | || | Logical OR | x || y | true | +------------+---------------------+-------------+---------+ | ! | Logical Not | !x | false | +------------+---------------------+-------------+---------+ Bitwise Operators The next table presents all of the bitwise operators provided by the Dragon language. Assume variable x = 8 and variable y = 2, then: +------------+-----------------------------+-------------+---------+ | Operator | Description | Example | Result | +============+=============================+=============+=========+ | & | Binary AND | x & y | 0 | +------------+-----------------------------+-------------+---------+ | | | Binary OR | x | y | 10 | +------------+-----------------------------+-------------+---------+ | ^ | Binary XOR | x ^ y | 10 | +------------+-----------------------------+-------------+---------+ | ~ | Binary Ones Complement | ~x | -9 | +------------+-----------------------------+-------------+---------+ | << | Binary Left Shift | x << y | 32 | +------------+-----------------------------+-------------+---------+ | >> | Binary Right Shift | x >> y | 2 | +------------+-----------------------------+-------------+---------+ Assignment Operators The next table presents all of the assignment operators provided by the Dragon language. Assume variable x = 8, then: +------------+-----------------------------+-------------+---------+ | Operator | Description | Example | Result | +============+=============================+=============+=========+ | = | Assignment | x = 8 | x=8 | +------------+-----------------------------+-------------+---------+ | += | Add AND assignment | x += 5 | x=13 | +------------+-----------------------------+-------------+---------+ | -= | Subtract AND assignment | x -= 3 | x=10 | +------------+-----------------------------+-------------+---------+ | *= | Multiply AND assignment | x *= 2 | x=20 | +------------+-----------------------------+-------------+---------+ | /= | Divide AND assignment | x /= 3 | x=6 | +------------+-----------------------------+-------------+---------+ | %= | Modulus AND assignment | x %= 2 | x=0 | +------------+-----------------------------+-------------+---------+ | <<= | Left shift AND assignment | x <<= 2 | x=0 | +------------+-----------------------------+-------------+---------+ | >>= | Right shift AND assignment | x >>= 2 | x=0 | +------------+-----------------------------+-------------+---------+ | &= | Bitwise AND assignment | x &= 4 | x=0 | +------------+-----------------------------+-------------+---------+ | |= | Bitwise OR and assignment | x |= 3 | x=3 | +------------+-----------------------------+-------------+---------+ | ^= | Bitwise XOR and assignment | x ^= 4 | x=7 | +------------+-----------------------------+-------------+---------+ Misc Operators ============== ====================================================================== Operator Description ============== ====================================================================== Start:End create list contains items from start to end [list items] define list items list[index] access list item ============== ====================================================================== Operator Precedence The next table presents operators from highest precedence (evaluated first) to lowest precedence. +----------------------------------------------------------------+ | Operator | +================================================================+ | . [] () {} | +----------------------------------------------------------------+ | - ~ :Literal [list items] | +----------------------------------------------------------------+ | ++ -- | +----------------------------------------------------------------+ | Start:End | +----------------------------------------------------------------+ | * / % | +----------------------------------------------------------------+ | + - | +----------------------------------------------------------------+ | << >> | +----------------------------------------------------------------+ | & | +----------------------------------------------------------------+ | \| ^ | +----------------------------------------------------------------+ | < > <= >= | +----------------------------------------------------------------+ | = != | +----------------------------------------------------------------+ | not | +----------------------------------------------------------------+ | and or | +----------------------------------------------------------------+ | Assignment = += -= \*= /= %= >>= <<= &= ^= \|= | +----------------------------------------------------------------+ Example: show 3+5*4 // prints 23 Dragon programming language