[an error occurred while processing this directive]

Boolean variables and operators

Bool data type

Our genlib library defines a data type bool which has two values -- the constants TRUE and FALSE.

Boolean operators

Operators on boolean values consit of:

Truth Tables for AND, OR and NOT

We define boolean operators by truth tables which give the desired output for every possible combination of inputs.

Truth table - (P and Q)

P Q P && Q
FALSE FALSE FALSE
FALSE TRUE FALSE
TRUE FALSE FALSE
TRUE TRUE TRUE

Truth table - (P or Q)

p Q P || Q
FALSE FALSE FALSE
FALSE TRUE TRUE
TRUE FALSE TRUE
TRUE TRUE TRUE

Truth table -
not P

P ! P
FALSE TRUE
TRUE FALSE

The Program

[an error occurred while processing this directive]

The Sample Run

[an error occurred while processing this directive]

A secret

How && and || evaluate

Flags

Less is more

BAD GOOD
 if (done==TRUE) ...
 if (done) ...
 if (done==FALSE) ...
 if (!done) ...
if (remaining == 0) 
{
   done = TRUE;
} 
else 
{
   done = FALSE;
} 
done = (remaining == 0);
[an error occurred while processing this directive]
Sunday, 16-Feb-1997 11:38:52 EST