Boolean Evaluation

Traditionally, the result of a logical or Boolean expression is considered true if it evaluates to 1 and false if it evaluates to 0.

In the D3 system, expressions that depend on a result of true or false also evaluate other values as true or false. This tends to vary somewhat between implementations. In generic D3, any nonzero integer that is positive or negative, evaluates to true. For example:

x = 5

if x then stop

Because x is a nonzero integer, the program takes the then branch and stops. In generic D3, any zero or null value evaluates to false. For instance:

y = ""

if y then stop else print "yup"

This prints yup because y is evaluated as false. Some D3 implementations additionally evaluate any negative numbers as false, and positive numbers as true. This also holds true for +, -, ., +., and -..

This means that you must test your system to determine how it handles true and false. This program does it:

loop

print "value to test " :

input value

until value = "quit" do

if value then print "true" else print "false"

repeat

Test it with negative numbers, null (Enter), positive numbers, letters, and so on.

A relational expression evaluates to 1 if the relation is true, and evaluates to 0 if the relation is false.

Relational operators have lower precedence than all arithmetic and string operators. Therefore, relational operators are only evaluated after all arithmetic and string operations have been evaluated.

In the logical expression:

x=y

the resolution of equal and unequal character pairs are handled as follows:

The case of characters does not affect a comparison if casing is off. For example:

if "a" = "A" then...

This is true with casing off. It is false with casing on.

Example(s)

equal displays, as both x and y evaluate to a numeric 1.

x = "1"

y = "001"

if x=y then crt 'equal' else crt 'not equal'

See Also

= Assignment Operator

> Relational Operator

alpha() Function

else Clause

for...next Statement

if Statement

ifr Statement

Logical Expressions

loop Statement

not() Function

Null Evaluation

num() Function

Precedence

precision Statement

then Clause