~: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
(edit)
Line 2: Line 2:


The '''~''' operator works as follows:
The '''~''' operator works as follows:
* The result is true if the converted operand is false
* The result is true if the operand is false
* The result is false if the converted operand is true.
* The result is false if the operand is true.


The '''~''' operator is equivalent to the '''NOT''' operator, with one difference: ~ works everywhere whereas NOT will only work in If and PRINT statements
The '''~''' operator is equivalent to the '''NOT''' operator, with one difference: ~ works everywhere whereas NOT will only work in If and PRINT statements


'''~''' is usually used in conjunction with an [[If]] [[statement]].
'''~''' is usually used in conjunction with an [[If]] [[statement]].
The following examples demonstrates the use of '''~''':
00010 let x =  1 ! same as true
00020 let y = ~x ! not true evaluates to false, which is 0 in BR
00010 let result = ( 2 < 5 ) ! 2 < 5 evaluates to true, which is 1 in BR
00020 print result          ! since result is 1, that's what will print on the screen


<noinclude>
<noinclude>

Revision as of 14:39, 9 January 2012

The logical unary negation operator ~ reverses the meaning of its operand. The operand must be numeric. Note that in BR, 1 means true and 0 means false.

The ~ operator works as follows:

  • The result is true if the operand is false
  • The result is false if the operand is true.

The ~ operator is equivalent to the NOT operator, with one difference: ~ works everywhere whereas NOT will only work in If and PRINT statements

~ is usually used in conjunction with an If statement.

The following examples demonstrates the use of ~:

00010 let x =  1 ! same as true
00020 let y = ~x ! not true evaluates to false, which is 0 in BR


00010 let result = ( 2 < 5 ) ! 2 < 5 evaluates to true, which is 1 in BR
00020 print result           ! since result is 1, that's what will print on the screen