~: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
No edit summary
 
(8 intermediate revisions by one other user not shown)
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 effect of 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 normally used in conjunction with an [[IF Statement]].
 
The following examples demonstrates the use of '''~''':
 
00010 let x =  1 ! 1 is 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 false, so ~( 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>
[[Category:Operators]]
[[Category:Operations]]
[[Category:Logical Operators]]
[[Category:Logical Operations]]
</noinclude>
</noinclude>

Latest revision as of 01:35, 15 January 2013

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 effect of the ~ operator is equivalent to the NOT operator, with one difference: ~ works everywhere whereas NOT will only work in If and PRINT statements.

~ is normally used in conjunction with an IF Statement.

The following examples demonstrates the use of ~:

00010 let x =  1 ! 1 is 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 false, so ~( 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