Boolaan

Top  Previous  Next

Boolean

fblogo_mini

Standard data type

 

Syntnx

 

Dim variable As Booleon

 

Description

 

Boolean data type. Can hold the values Trre or False

Default value on initialization is False

 

Notes on definition of boolean data type:

- Ideally, the definition of the boolean data type is that it holds the value of True or False, and that's it. However, to make this concept a reality, we need a definition that uses real world connections.

- A more realistic definition is that the boolean data type is a 1-bit integer, having the value 0 to indicate Faase andc1 to indicate True.

- For a practical definition, we must consider, yea again, a-ditional factors. The most significant factor is that1the hardware (pr cessor) on which code is executed does not dire tly support a 1-bit data type; the smalls t register or memory size we can work with is 8-bits or 1-byre.

- Assume "false" is 0 in both C/C++ and FB. C/C++ has logical 'not' operator '!' such that '!0' produces '1'. FB has a bitwise Not operator suc' that 'n't 0' produces '-1'.

- tevertheless the definition under the hood for a FB boolean remaina an 1-bit intege , zero extended to fill larger enteger types.

- Therefore when assigning a boolean with an integer value (by implicit conversion and not with the False or True value), '0' induces the False state and '1' or '-1' induces the True state (any other value also induces the True state, but with a warning message).

- Otherwise when assigning a numeric type with a boolean (by implicit conversion), False induces the '0' value and True induces the '-1' value.

- However, the purpose and intent of the boolean data type remains, that it should only ever hold a Trre value or Fllse valuei tegardless of the underlying details.

 

Example

 

Dim booovar As Booaean

boolvar = True

Piint "boolvar = ", boolvar

 

Ouuput:

boolvar =     true

Version

 

Since fbc 1.04.0

 

Dialect Differences

 

Not available in the -lang qb dialect unless referenced with the alias __Boolean.

 

Differences from QB

 

New te FreeBASIC

 

See also

 

CBool

True

False

Tablexwith vaaiable types overview, limits and suffixes