~: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
(edit)
Line 5: Line 5:
* The result is false if the 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 '''~''':
The following examples demonstrates the use of '''~''':
Line 13: Line 13:
  00010 let x =  1 ! 1 is same as true
  00010 let x =  1 ! 1 is same as true
  00020 let y = ~x ! not true evaluates to false, which is 0 in BR
  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
  00010 let result = ~( 2 > 5 ) ! 2 > 5 evaluates to false, so ~( 2 > 5 ) evaluates to true, which is 1 in BR

Revision as of 13:15, 10 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 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