From BeebWiki
Jump to: navigation, search

FALSE is a BASIC numeric constant whose value represents the Boolean value false.

Availability Present in all original versions of BBC BASIC.
Syntax BASIC I-V <num-var> = FALSE
Token (hex) BASIC I-V A3 (rvalue)
Description BASIC I-V An integer constant equal to 0, representing the value false in BASIC Boolean logic.
Associated keywords TRUE


FALSE is a numeric constant used in BASIC to represent a false condition. In Boolean algebra all expressions (Boolean expressions) represent a condition that can be tested and found to be true or false. IF, UNTIL and WHILE all use a Boolean expression to decide which piece of code to execute next.

For instance, a Boolean expression in BASIC typically looks like temperature >= -273.15 or attempts%<10 AND (result% AND &18) = 0. It will evaluate to one of the constants, TRUE or FALSE.

FALSE is also a valid Boolean expression, and represents 'a condition that is never fulfilled'. 1 = 2 evaluates to FALSE but takes longer to compute.

In BASIC there is no Boolean data type, as there is in some high-level languages. Integers are used instead. It was decided to define FALSE = 0 as this is the easiest single integer to test for in 6502 machine code. The value of TRUE follows from the identity:


and due to the operation of NOT, and the two's-complement arithmetic used on integers, TRUE evaluates to -1.

All numeric values besides TRUE and FALSE are invalid in Boolean expressions. As inputs to IF, UNTIL and WHILE they happen to have the same effect as TRUE, but they violate the law of the excluded middle:

((n = TRUE) OR (n = FALSE)) = TRUE

Therefore only TRUE and FALSE work correctly as Boolean operands to AND, OR and NOT, as these three are always 'bitwise' operators.

Syntactically speaking, TRUE and -1, and FALSE and 0, are interchangeable as they are both <numeric> expressions. But by convention TRUE and FALSE are used in BASIC code to mark that the numeric expression is being used as a Boolean value. For example in the idiom:


meaning, repeat the code inside forever. The effect is the same as:


-- beardo 22:44, 13 June 2007 (BST)