Liberty BASIC Help Online |
---|

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".

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].

=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

When evaluating multiple conditions, each condition must be placed inside parentheses, as in the examples below.

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]

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.

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].

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

Copyright (C) 2003 Shoptalk Systems

Liberty BASIC - http://www.libertybasic.com/