TOC < Back Next > Updated: 6-Feb-2009 Edit History

# REBOL 3 Datatypes: Logic!

## Concept

The logic! datatype consists of two states representing true and false. They are often returned from comparisons such as:

```age: 100
probe age = 100
true```
```time: 10:31:00
probe time < 10:30
false```
```str: "this is a string"
probe (length? str) > 10
true```

The logic! datatype is most commonly used as parameters to conditional functions such as if, while, and until:

```if age = 100 [print "Centennial human"]
Centennial human```
```while [time > 6:30] [
send person "Wake up!"
wait [0:10]
]```

The complement of a logic value is obtained from the not function:

```there: place = "Ukiah"
if not there [...]```

## Format

Normally, logic values are retrieved from the evaluation of comparison expressions. However, words can be set to a logic value and used to turn the word on or off:

```print-me: false
print either print-me ["turned on"]["turned off"]
turned off```
```print-me: true
print either print-me ["turned on"]["turned off"]
turned on```

The false value is not equivalent to integer zero or none!. However, in conditional expressions false and none! have the same effect:

```print-me: none
print either print-me ["turned on"]["turned off"]
turned off```

Just about any value assigned to a word has the same effect as true:

```print-me: "just a string"
print either print-me ["turned on"]["turned off"]
turned on```
```print-me: 11-11-1999
print either print-me ["turned on"]["turned off"]
turned on```

The following words are predefined to hold logic values:

```true
on     ;same as true
yes    ;same as true
false
off    ;same as false
no     ;same as false```

So, instead of true and false, when it makes sense, the words on and off, or yes and no can be used instead:

```print-me: yes
print either print-me ["turned on"]["turned off"]
turned on```
```print-me: no
print either print-me ["turned on"]["turned off"]
turned off```
```print-me: on
print either print-me ["turned on"]["turned off"]
turned on```
```print-me: off
print either print-me ["turned on"]["turned off"]
turned off```

## Creation

The to-logic function converts integer! or none! values to the logic! datatype:

```probe to-logic 0
false```
```probe to-logic 200
true```
```probe to-logic none
false```
```probe to-logic []
true```
```probe to-logic "a"
true```
```probe to-logic none
false```

## Related

Use logic? to determine whether a value is a logic! datatype.

```probe logic? 1
false```
```probe logic? on
true```
```probe logic? false
true```

Use the functions form, print, and mold to print a logic value:

```probe form true
true```
```probe mold false
false```
```print true
true```

 TOC < Back Next > Feedback Admin