Liberty BASIC Help Online

Boolean Evaluations
What are booleans evaluations?
A boolean value is either true or false. When used as types in CallDLL, booleans evaluate to (0 = false), (nonzero = true).  A true value is any value not zero, but is usually considered to be either "1" or "-1".
 
Boolean Conditions
Tests that are placed into conditional clauses like IF/THEN, WHILE/WEND, and CASE statements return a boolean value. Here is an evaluation:
 
if x < 3 then [doSomething]
 
The code is evaluating the condition (x < 3) and branching to the [doSomething] label if the condition is TRUE.  If the value of x is 1, then the condition evaluates to TRUE and the program branches to [doSomething].  If the value of x is 7, then the condition evaluates to FALSE and the program does NOT branch to [doSomething].
 
Boolean Operators
=a = ba is equal to b
<=a <= ba is less than or equal to b
>a > ba is less than b
>=a >= ba is less than or equal to b
<>a <> ba is not equal to b
 
Multiple Conditions
When evaluating multiple conditions, each condition must be placed inside parentheses, as in the examples below.
 
 
AND - both conditions must be met for the test to evaluate to TRUE.
a = 2  : b = 5
If (a<4) and (b=5) then [doSomething]
 
In this code, (a must be less than 4) AND (b must be equal to 5) for the program to branch to [doSomething].  Since both of these conditions are true, the program will advance to [doSomething]
 
a = 14  : b = 5
If (a<4) and (b=5) then [doSomething]
 
This similar example evaluates to FALSE because (a is not less than 4), so the program will not advance to [doSomething]
 
 
OR - at least one of the conditions must be met for the test to evaluate to TRUE.
 
a = 14  : b = 5
If (a<4) OR (b=5) then [doSomething]
 
In this code, at least one of the conditions (a must be less than 4) OR (b must be equal to 5) must evaluate to TRUE for the program to branch to [doSomething].  Since the example shows that (b is equal to 5), the program will advance to [doSomething], because at least one of the conditions evaluates to TRUE.
 
 
XOR - only one of the conditions must be met for the test to evaluate to TRUE.
 
a = 14  : b = 5
If (a<4) XOR (b=5) then [doSomething]
 
In this code, only one of the conditions (a is less than 4) OR (b is to 5) must evaluate to TRUE for the program to branch to [doSomething].  In the example, only the second condition evaluates to true, so the program will advance to [doSomething].
 
a = 2  : b = 5
If (a<4) XOR (b=5) then [doSomething]
 
In the second XOR example, both conditions evaluate to true, so the program will NOT advance to [doSomething].
 
 
NOT - reverses the value.
 
If NOT((a<4) AND (b=5)) then [doSomething]
 
In this code, both of the conditions (a must NOT be less than 4) AND (b must be equal to 5) must evaluate to TRUE for the program to branch to [doSomething].
 
BOOLEAN TRUTH TABLE
 
Input1OP Input2 = Result
 
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
 
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
 
 
See also:  Bitwise Operations


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/