NOT - QB64 Wiki

NOT

From QB64 Wiki

Jump to: navigation, search

NOT is a Boolean logical operator that will change a False statement to a True one and vise-versa.


Syntax:

True = -1: False = NOT True


  • In Qbasic, True = -1 and False = 0 in boolean logic and evaluation statements.
  • NOT evaluates ONE value and returns the opposite. Yes, NOT 0 = -1 in Basic.
  • Often called a negative logic operator, it returns the opposite of a value as true or false.
Relational Operators:
Symbol Condition Example Usage
<  Less than  IF a < b THEN
>  Greater than  IF a > b THEN
=  Equal  IF a = b THEN
<=  Less than or equal  IF a <= b THEN
>=  Greater than or equal  IF a >= b THEN
<>  NOT equal  IF a <> b THEN


The results of the bitwise logical operations, where A and B are operands, and T and F indicate that a bit is set or not set:
Operands Operations
A B NOT B A AND B A OR BA XOR BA EQV BA IMP B
T T F T T F T T
T F T F T T F F
F T F F T T F T
F F T F F F T T
Note that the Relational Operations return negative one (-1, all bits set) and zero (0, no bits set) for true and false, respectively.
This allows relational tests to be inverted and combined using the bitwise logical operations.



Example 1: Alternating between two conditions in a program loop.

DO switch = NOT switch 'NOT changes value from -1 to 0 and vice-versa LOCATE 10, 38 IF switch THEN PRINT "True!" ELSE PRINT "False" SLEEP k$ = INKEY$ LOOP UNTIL k$ = CHR$(27) ' escape key quit


Example 2: Reading a file until it reaches the End Of File.

DO WHILE NOT EOF(1) INPUT #1, data1, data2, data3 LOOP

Explanation: EOF will return 0 until a file ends. NOT converts 0 to -1 so that the loop continues to run. When EOF becomes -1, NOT converts it to 0 to end the loop.


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page