~: Difference between revisions
Jump to navigation
Jump to search
(edit) |
(edit) |
||
Line 15: | Line 15: | ||
00010 let result = ( 2 | 00010 let result = ~( 2 > 5 ) ! 2 > 5 evaluates to false, so ~( 2 > 5 ) evaluates to true, which is 1 in BR | ||
00020 print result | 00020 print result ! since result is 1, that's what will print on the screen | ||
<noinclude> | <noinclude> |
Revision as of 14:40, 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 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