# Boolean values

**Boolean values**

You are encouraged to solve this task according to the task description, using any language you may know.

- Task

Show how to represent the boolean states "**true**" and "**false**" in a language.

If other objects represent "**true**" or "**false**" in conditionals, note it.

- Related tasks

## Contents

- 1 360 Assembly
- 2 8051 Assembly
- 3 8th
- 4 ACL2
- 5 Ada
- 6 ALGOL 68
- 7 ALGOL W
- 8 AppleScript
- 9 Applesoft BASIC
- 10 AutoHotkey
- 11 AWK
- 12 Axe
- 13 BASIC
- 14 BASIC256
- 15 BBC BASIC
- 16 bc
- 17 Befunge
- 18 Bracmat
- 19 Brainf***
- 20 C
- 21 C++
- 22 C#
- 23 Clean
- 24 Clojure
- 25 CMake
- 26 COBOL
- 27 CoffeeScript
- 28 Common Lisp
- 29 Component Pascal
- 30 D
- 31 Delphi
- 32 Déjà Vu
- 33 DWScript
- 34 Dylan
- 35 E
- 36 EchoLisp
- 37 EGL
- 38 Elena
- 39 Elixir
- 40 Elm
- 41 Emacs Lisp
- 42 Erlang
- 43 Excel
- 44 F#
- 45 Factor
- 46 FALSE
- 47 Fantom
- 48 Forth
- 49 Fortran
- 50 FreeBASIC
- 51 Futhark
- 52 Gambas
- 53 GAP
- 54 Go
- 55 Groovy
- 56 Haskell
- 57 HicEst
- 58 HolyC
- 59 I
- 60 Icon and Unicon
- 61 Idris
- 62 Inform 6
- 63 Inform 7
- 64 J
- 65 Java
- 66 JavaScript
- 67 jq
- 68 Julia
- 69 KonsolScript
- 70 Kotlin
- 71 LabVIEW
- 72 Lasso
- 73 LFE
- 74 Liberty BASIC
- 75 Lingo
- 76 Little
- 77 LiveCode
- 78 Logo
- 79 Lua
- 80 Maple
- 81 Mathematica
- 82 MATLAB
- 83 Maxima
- 84 Metafont
- 85 Mirah
- 86 Modula-2
- 87 Modula-3
- 88 Monte
- 89 MUMPS
- 90 Nemerle
- 91 NetRexx
- 92 Nim
- 93 Oberon-2
- 94 Objeck
- 95 Objective-C
- 96 OCaml
- 97 Octave
- 98 Oforth
- 99 Ol
- 100 ooRexx
- 101 Order
- 102 Oz
- 103 PARI/GP
- 104 Pascal
- 105 Perl
- 106 Perl 6
- 107 Phix
- 108 PHP
- 109 PicoLisp
- 110 Pike
- 111 PL/I
- 112 Pony
- 113 PowerBASIC
- 114 PostScript
- 115 PowerShell
- 116 PureBasic
- 117 Python
- 118 R
- 119 Racket
- 120 Raven
- 121 REBOL
- 122 Retro
- 123 REXX
- 124 Ring
- 125 Ruby
- 126 Run BASIC
- 127 Rust
- 128 Sather
- 129 Scala
- 130 Scheme
- 131 Seed7
- 132 Self
- 133 Sidef
- 134 Slate
- 135 Smalltalk
- 136 smart BASIC
- 137 SNUSP
- 138 SPL
- 139 Standard ML
- 140 Stata
- 141 Swift
- 142 Tcl
- 143 TI-89 BASIC
- 144 Trith
- 145 uBasic/4tH
- 146 UNIX Shell
- 147 Ursa
- 148 Visual Basic
- 149 Vim Script
- 150 XLISP
- 151 XPL0
- 152 XSLT
- 153 zkl

## 360 Assembly[edit]

The are no TRUE or FALSE constants in 360 Assembly; but an often used convention is :

FALSE DC X'00'

TRUE DC X'FF'

## 8051 Assembly[edit]

A single bit represents true or false. By convention, 0 (cleared) is false, 1 (set) is true. In the following, "bit" represents the direct address of any of the 256 directly accessible bits.

clr bit ; clears

setb bit ; sets

## 8th[edit]

In 8th, any non-zero number is true, as is the specific boolean value 'true'. Everything else evaluates as 'false' (including the boolean value, 'false')

## ACL2[edit]

Same as Boolean Values#Common Lisp.

## Ada[edit]

Ada has a predefined discrete type with the specification:

type Boolean is (False, True);

with Boolean lattice and relational operations defined on it. See RM A.1.

## ALGOL 68[edit]

ALGOL 68 Enforces strong typing and so has few default coercions. The appropriate operators must be used to convert to and from **bool**[ean] and the following code demonstrates principle conversions:

BOOL f = FALSE, t = TRUE;

[]BOOL ft = (f, t);

STRING or = " or ";

FOR key TO UPB ft DO

BOOL val = ft[key];

UNION(VOID, INT) void = (val|666|EMPTY);

REF STRING ref = (val|HEAP STRING|NIL);

INT int = ABS val;

REAL real = ABS val;

COMPL compl = ABS val;

BITS bits = BIN ABS val; # or bitspack(val); #

BYTES bytes = bytes pack((val|"?"|null char)*bytes width);

CHAR char = (val|"?"|null char);

STRING string = (val|"?"|"");

print((((val | "TRUE" | "FALSE" ), ": ", val, or, (val|flip|flop), new line)));

print((" void: ", " => ", (void|(VOID):FALSE|TRUE), new line));

print((" ref: ", " => ", ref ISNT REF STRING(NIL), new line));

print((" int: ", int , " => ", int /= 0, new line));

print((" real: ", real , " => ", real /= 0, new line));

print((" compl: ", compl , " => ", compl /= 0, new line));

print((" bits: ", bits , " => ", ABS bits /= 0, or, bits /= 2r0, or,

bits width ELEM bits, or, []BOOL(bits)[bits width], new line));

print((" bytes: """, STRING(bytes) , """ => ", 1 ELEM bytes /= null char, or,

STRING(bytes) /= null char*bytes width, or,

STRING(bytes)[1] /= null char, new line));

print((" char: """, char , """ => ", ABS char /= 0 , or, char /= null char, new line));

print(("string: """, string , """ => ", string /= "", or, UPB string /= 0, new line));

print((new line))

OD

- Output:

FALSE: F or F void: => F ref: => F int: +0 => F real: +0.00000000000000e +0 => F compl: +0.00000000000000e +0+0.00000000000000e +0 => F bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF => F or F or F or F bytes: "" => F or F or F char: "" => F or F string: "" => F or F TRUE: T or T void: => T ref: => T int: +1 => T real: +1.00000000000000e +0 => T compl: +1.00000000000000e +0+0.00000000000000e +0 => T bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFT => T or T or T or T bytes: "????????????????????????????????" => T or T or T char: "?" => T or T string: "?" => T or T

Note: The **string** **repr**[esentation] of **false** and **true** are defined by the variables *flop* and *flip* respectively.

## ALGOL W[edit]

The boolean type is called logical in Algol W - the values are represented by the keywords true and false. Numbers, strings etc. cannot be used where logical values are required.

## AppleScript[edit]

AppleScript has built-in boolean keywords `true`

and `false`

. Numbers do not work in place of boolean expressions.

## Applesoft BASIC[edit]

IF statement condition treats any non-zero numeric value as true. Comparison operators evaluate to 1 (true) or 0 (false).

Examples:? 2 = 3

? 2 = 2

IF 7 THEN ?"HELLO"

- Output:

0 1 HELLO

## AutoHotkey[edit]

When an expression is required to evaluate to true or false (such as an `IF`

-statement), a blank or zero result is considered false and all other results are considered true. Operators such as `NOT`

/`AND`

/`OR`

/`>`

/`=`

/`<`

automatically produce a true or false value: they yield 1 for true and 0 for false. A variable can be used to hold a false value simply by making it blank or assigning 0 to it. The words 'true' and 'false' are built-in variables containing 1 and 0. They can be used to make a script more readable.

## AWK[edit]

There is no keyword for true or false in awk. In awk, any nonzero numeric value or any nonempty string value is true. Any other value (zero or the null string "") is false. Values containing only zeros may produce true or false depending on whether they are obtained from the datasource or by assignment, and different results may be obtained according to which version of awk is being used.

- Reference: AWK Truth values

In the following example we use zero for false, and one for true to assign boolean values. However, this is just a convention, so other values may also have been used:

BEGIN {

# Do not put quotes round the numeric values, or the tests will fail

a = 1 # True

b = 0 # False

# Boolean evaluations

if (a) { print "first test a is true" } # This should print

if (b) { print "second test b is true" } # This should not print

if (!a) { print "third test a is false" } # This should not print

if (!b) { print "forth test b is false" } # This should print

# Boolean evaluation using comparison against zero

if (a == 0) { print "fifth test a is false" } # This should not print

if (b == 0) { print "sixth test b is false" } # This should print

if (a != 0) { print "seventh test a is true" } # This should print

if (b != 0) { print "eighth test b is true" } # This should not print

}

## Axe[edit]

In Axe, there are no keywords for true and false. Any expression that evaluates to zero is considered false, and any expression that evaluates to non-zero is considered true. Unlike other languages, there is no canonical value for true (e.g. 1).

## BASIC[edit]

Most BASICs have no keywords for true and false. Boolean expressions evaluate to 0 when false, and a non-zero value (traditional versions of basic use a value of one, although some variants use a value of negative one) when true. Numbers also work in place of boolean expressions following those rules.

10 LET A%=0

20 LET B%=NOT(A%)

30 PRINT "THIS VERSION OF BASIC USES"

40 PRINT B%; " AS ITS TRUE VALUE"

50 IF A% THEN PRINT "TEST ONE DOES NOT PRINT"

60 IF B% THEN PRINT "TEST TWO DOES PRINT"

70 IF A%=0 THEN PRINT "TEST THREE (FALSE BY COMPARISON) DOES PRINT"

80 IF B%=0 THEN PRINT "TEST FOUR (FALSE BY COMPARISON) DOES NOT PRINT"

90 IF A%<>0 THEN PRINT "TEST FIVE (TRUE BY COMPARISON) DOES NOT PRINT"

100 IF B%<>0 THEN PRINT "TEST SIX (TRUE BY COMPARISON) DOES PRINT"

110 END

### BaCon[edit]

' Boolean TRUE and FALSE are non-zero and zero constants

a = TRUE

b = FALSE

PRINT a, ", ", b

IF 0 THEN PRINT "TRUE" : ELSE PRINT "FALSE"

IF 1 THEN PRINT "TRUE"

IF 2 THEN PRINT "TRUE"

- Output:

prompt$ bacon boolean.bac Converting 'boolean.bac'... done, 8 lines were processed in 0.004 seconds. Compiling 'boolean.bac'... cc -c boolean.bac.c cc -o boolean boolean.bac.o -lbacon -lm Done, program 'boolean' ready. prompt$ ./boolean 1, 0 FALSE TRUE TRUE

## BASIC256[edit]

' BASIC256 used numbers to represent true and false

' values. Zero is false and anything else is true.

' The built in constants true and false exist

' and represent one and zero respectively.

print false

print true

## BBC BASIC[edit]

REM BBC BASIC uses integers to represent Booleans; the keywords

REM FALSE and TRUE equate to 0 and -1 (&FFFFFFFF) respectively:

PRINT FALSE

PRINT TRUE

## bc[edit]

POSIX bc doesn't define Boolean values (i.e. it's up to the programmer which values represent false and true).

In GNU bc, 0 is false and any other value is true (but the result of a boolean expression will always be 1 if it is true).

## Befunge[edit]

Zero is false, non-zero is true. This is only used by the horizontal and vertical switch operators (`_`

and `|`

).

## Bracmat[edit]

Bracmat operates with success and failure instead of true and false. Success and failure play the same role as true and false in conditional tests, but they are not values like true and false. Instead, success and failure are properties of expressions in addition to values. The simplest failing expression is the atomic expression `~`

. The simplest succeeding atomic expression is the empty string `""`

(or `()`

). A slightly more complex failing expression is `1+1:3`

, which postulates that `3`

matches the result of adding `1`

and `1`

, while `1+1:2`

of course succeeds.

## Brainf***[edit]

Zero is false, non-zero is true. This is only used by the loop brackets (`[`

and `]`

).

## C[edit]

In C, a value which is equal to 0 is false, while a value which is not equal to 0 is true. Relational and logical operators evaluate to 0 for false and 1 for true. Any of the following can be used:

- any integer type, where 0 gives false, and any other value gives true (note that in C, character types are also integer types, therefore this also applies to characters: the
`'\0'`

character is false) - any floating point type, where again, 0 gives false and everything else gives true
- any enumeration type, again 0 gives false, anything else true
- any pointer type, where the null pointer gives false and any other pointer gives true
- in C99, the boolean type
`bool`

(defined in header`<stdbool.h>`), where`true`

gives true and`false`

gives false - in C99, any complex number type, where 0 (0 real and 0 imaginary) gives false, anything else gives true

## C++[edit]

In C++, there are the constants `true`

and `false`

to represent those values. However, there are numerous implicit conversions to `bool`

, therefore in conditions (and other contexts expecting boolean values), any of the following can be used:

- any integer type, where 0 converts to false, and any other value converts to true (note that in C++, character types are also integer types, therefore this also applies to characters: the
`'\0'`

character is false) - any floating point type, where again, 0 gives false and everything else gives true
- any enumeration type, again 0 gives false, anything else true
- any pointer type, where the null pointer gives false and any other pointer gives true
- any user-defined type with an implicit conversion operator either to
`bool`

or to a built-in type which itself can be converted to`bool`

(i.e. any of the above). The C++ standard library contains one such implicit conversion: the implicit conversion of a stream`s`

to`bool`

gives`!s.fail()`

## C#[edit]

In C#, there are the reserved keywords `true`

and `false`

. Variables to hold these values are declared as either `bool`

or `Boolean`

. These types are identical, as `bool`

is just shortand for `Boolean`

. The collection type `BitArray`

returns its values as `Boolean`

, packing 8 values into each byte (In contrast, the `Boolean`

type uses the entire byte for one value).

Unlike C/C++, there is no conversion in C# between other types and `Boolean`

.

## Clean[edit]

The standard library defines a data type `Bool`

, which has exactly two members:

::Bool = False | True

In addition to all the functionality of any other Clean algebraic data type (e.g. pattern matching), and the specified derived typeclass instances, the built-in guard (“`|`

”) and `if`

syntaxes use Bool.

As with any other Clean data type, there are no automatic conversions of other types to Bool.

## Clojure[edit]

The boolean constants are *true* and *false*. In a conditional context, the only false values are *false* and *nil* -- every other value is true.

## CMake[edit]

foreach(var 1 42 ON yes True y Princess

0 OFF no False n Princess-NOTFOUND)

if(var)

message(STATUS "${var} is true.")

else()

message(STATUS "${var} is false.")

endif()

endforeach(var)

-- 1 is true. -- 42 is true. -- ON is true. -- yes is true. -- True is true. -- y is true. -- Princess is true. -- 0 is false. -- OFF is false. -- no is false. -- False is false. -- n is false. -- Princess-NOTFOUND is false.

The strings "0", "OFF", "NO", "FALSE" and "N" (ignoring case) are false. Any string ending with "-NOTFOUND" (ignoring case) is false. All other strings are true.

Scripts that want `if(TRUE)`

should require CMake 2.8; do refer to cmake --help-policy CMP0012.

## COBOL[edit]

### Booleans[edit]

Booleans are defined as any data item having a `PICTURE`

made up of ones.

01 some-bool PIC 1 BIT.

The boolean literals `B"1"`

and `B"0"`

represent true and false, respectively.

### Conditions[edit]

Prior to COBOL 2002, there was no boolean data type, only *condition names* which could be used in conditional expressions. Condition names are subordinate to another data item, have the level-number 88, and are defined with the value(s) which their parent data item must have for them to be set to true. They can be defined like so:

01 X PIC 9.

88 X-Is-One VALUE 1.

88 X-Is-Even VALUE 0 2 4 6 8.

88 X-Larger-Than-5 VALUE 6 THRU 9.

Conditions can be `SET`

to `TRUE`

or `FALSE`

. Setting a condition to `TRUE`

will move the (first) value in the `VALUE`

clause to the parent data item. In COBOL 2002, an optional `FALSE`

clause was added which allowed the condition to be `SET`

to `FALSE`

and consequently set the parent data item to the specified value in the clause. A `FALSE`

clause can only have one value. An example of conditions in action:

PROGRAM-ID. Condition-Example.

DATA DIVISION.

WORKING-STORAGE SECTION.

01 Foo PIC 9 VALUE 5.

88 Is-Not-Zero VALUE 1 THRU 9

WHEN SET TO FALSE IS 0.

PROCEDURE DIVISION.

Main.

PERFORM Is-Foo-Zero

SET Is-Not-Zero TO FALSE

PERFORM Is-Foo-Zero

SET Is-Not-Zero TO TRUE

PERFORM Is-Foo-Zero

GOBACK

.

Is-Foo-Zero.

IF Is-Not-Zero

DISPLAY "Foo is not zero, it is " Foo "."

ELSE

DISPLAY "Foo is zero."

END-IF

.

- Output:

Foo is not zero, it is 5. Foo is zero. Foo is not zero, it is 1.

## CoffeeScript[edit]

CoffeeScript is largely based on JavaScript, but that may only serve to confuse you. Your best bet is to learn all the cases:

h1 = {foo: "bar"}

h2 = {foo: "bar"}

true_expressions = [

true

1

h1? # because h1 is defined above

not false

!false

[]

{}

1 + 1 == 2

1 == 1 # simple value equality

true or false

]

false_expressions = [

false

not true

undeclared_variable?

0

''

null

undefined

h1 == h2 # despite having same key/values

1 == "1" # different types

false and true

]

## Common Lisp[edit]

The only value in Common Lisp that is false is the symbol `nil`

; all other values are true. The symbol `t`

is the canonical true value.

Considered as variables, `nil`

and `t`

are bound to themselves ("self-evaluating"). `nil`

, as well as being false, is used as the empty list; i.e. an empty list is false.

For more information, follow the links from CLHS: Type BOOLEAN.

## Component Pascal[edit]

VAR

b,c: BOOLEAN;

...

b := TRUE;

c := FALSE;

...

## D[edit]

In D, there are constants `false`

and `true`

to represent their respective values (that also implicitly convert to 0 and 1).
Implicit conversions to boolean are listed below:

- Any integer type, where 0 converts to false, and any other value converts to true;
- Any floating point type, where again, 0 gives false and everything else (but NaNs) gives true;
- Any enumeration type, again 0 gives false, anything else true;
- Any pointer type, where the null pointer gives false and any other pointer gives true;
- Any class reference type, using the "is" operator, the null reference gives false and any other reference gives true;
- Any user-defined type with an implicit conversion operator (opCast) either to bool or to a built-in type which itself can be converted to bool.

## Delphi[edit]

Delphi (like Pascal) has standard ordinal `Boolean`

type with two values: `True`

and `False`

, `Ord(False) = 0`

, `Ord(True) = 1`

Delphi also defines `BOOL`

, `ByteBool`

, `WordBool`

and `LongBool`

types (to simplify C functions' import). For these types zero value is `False`

and any nonzero value is `True`

.

## Déjà Vu[edit]

Déjà Vu has `true`

and `false`

, two numbers that are equal to 1 and 0 respectively. Every object has a truth value. The only falsy things are numbers equal to zero, empty lists and dictionaries, and zero-length strings and blobs.

## DWScript[edit]

The standard `Boolean`

type has two values: `True`

and `False`

, with `Ord(False) = 0`

and `Ord(True) = 1`

.

## Dylan[edit]

#t // <boolean> true

#f // <boolean> false

For the purpose of conditional statements, all objects other than `#f` evaluate to true.

## E[edit]

E defines two basic objects `true`

and `false`

, and the `boolean`

guard which accepts them. All builtin operations which take booleans (e.g. the `if`

control structure) coerce the input to boolean.

? if (true) { "a" } else { "b" }

# value: "a"

? if (false) { "a" } else { "b" }

# value: "b"

? if (90) { "a" } else { "b" }

# problem: the int 90 doesn't coerce to a boolean

No objects in the standard library coerce to boolean, but user-written objects may choose to do so; they can then be used in place of booleans.

? def bowlian {

> to __conformTo(guard) {

> if (guard == boolean) { return true }

> }

> }

> if (bowlian) { "a" } else { "b" }

# value: "a"

## EchoLisp[edit]

"All that which is not false is true" - Attribué à L. Wittgenstein - The only false value is the boolean #f. **All** other objects, including the empty list or null or 0 ..- evaluate to #t = true.

(not #t) → #f

(not #f) → #t

(not null) → #f

(not 0) → #f

## EGL[edit]

In EGL boolean is a primitive type, however it acts the same as an integer (type int). A boolean and an int accept integer values aswel as true and false keywords (which represent resp. 1 and 0). A boolean is always true except when it has value 0 (or keyword false). A boolean can be converted to a string ("true" or "false") using StrLib.booleanAsString(boolean);

myBool boolean = 0;

SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));

myBool = 1;

SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));

myBool = 2;

SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));

myBool = false;

SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));

myBool = true;

SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));

myInt int = 0;

SysLib.writeStdout("myInt: " + StrLib.booleanAsString(myInt));

myInt = 1;

SysLib.writeStdout("myInt: " + StrLib.booleanAsString(myInt));

myInt = 2;

SysLib.writeStdout("myInt: " + StrLib.booleanAsString(myInt));

myInt = false;

SysLib.writeStdout("myInt: " + StrLib.booleanAsString(myInt));

myInt = true;

SysLib.writeStdout("myInt: " + StrLib.booleanAsString(myInt));

- Output:

myBool: false myBool: true myBool: true myBool: false myBool: true myInt: false myInt: true myInt: true myInt: false myInt: true

## Elena[edit]

ELENA uses the system'BaseBoolValue class, which has two singleton sub-classes: system'true and system'false. E.g. an expression like 5 == 5 returns system'true. There is a Boolean variable : system'Boolean.

## Elixir[edit]

Elixir utilizes Erlang's definition of boolean types; they're defined as the atoms `:true` and `:false`. No other type is equal to true or false.

iex(1)> true === :true

true

iex(2)> false === :false

true

iex(3)> true === 1

false

nil (also defined as an atom, `:nil`) is not equal to false.

iex(4)> nil === :nil

true

iex(5)> nil === false

false

## Elm[edit]

--True and False directly represent Boolean values in Elm

--For eg to show yes for true and no for false

if True then "yes" else "no"

--Same expression differently

if False then "no" else "yes"

--This you can run as a program

--Elm allows you to take anything you want for representation

--In the program we take T for true F for false

import Html exposing(text,div,Html)

import Html.Attributes exposing(style)

type Expr = T | F | And Expr Expr | Or Expr Expr | Not Expr

evaluate : Expr->Bool

evaluate expression =

case expression of

T ->

True

F ->

False

And expr1 expr2 ->

evaluate expr1 && evaluate expr2

Or expr1 expr2 ->

evaluate expr1 || evaluate expr2

Not expr ->

not (evaluate expr)

--CHECKING RANDOM LOGICAL EXPRESSIONS

ex1= Not F

ex2= And T F

ex3= And (Not(Or T F)) T

main =

div [] (List.map display [ex1, ex2, ex3])

display expr=

div [] [ text ( toString expr ++ "-->" ++ toString(evaluate expr) ) ]

--END

## Emacs Lisp[edit]

Symbol `nil`

is false and symbol `t`

is true. Both are self-evaluating, being variables whose value is their own symbol. See the elisp manual for more.

In an `if`

and similar, `nil`

is false and anything else is true. To make that clear docstrings etc say "non-nil" for true. (See last item in elisp manual documentation tips.)

## Erlang[edit]

Erlang doesn't technically define boolean types. Instead, the atoms `true` and `false` are used. However, they are integrated well enough into the language there should be no problem with that as long as you don't expect false and true to mean anything but literal false and true.

1> 1 < 2.

true

2> 1 < 1.

false

3> 0 == false.

false

## Excel[edit]

The Logical category of functions includes the constants TRUE() and FALSE() which are displayed without the parantheses in cells. There are logical functions such as AND and OR too. For an AND truth table of two variables, take 3 cells, say A1,B1 and C1. In C1 type in :

=AND(A1;B1)

Copy this until C4. Now as values are filled in from A1-A4 and B1-B4, C1-C4 gets updated.

0 0 FALSE

0 1 FALSE

1 0 FALSE

1 1 TRUE

## F#[edit]

The type bool is an abbreviation for the .NET framework type `System.Boolean`

.

type bool = System.Boolean

Instances of this type have values of either `true`

or `false`

.

## Factor[edit]

In Factor any value except `f`

is true, with `t`

being the canonical true value.

## FALSE[edit]

Zero is false and non-zero is true. This is used by the if and while operators (**?** and **#**). Comparators (**=** and **<**) yield -1 for true and 0 for false.

## Fantom[edit]

Conditional statements must return a `sys::Bool`

, and the only two values are `true`

and `false`

.

## Forth[edit]

In conditionals, zero is false, non-zero is true. There are predefined constants for the canonical forms. For FORTH-83 or later, FALSE is zero and TRUE is -1 (all bits set). For earlier FORTH standards, FALSE is zero and TRUE is 1.

TRUE . \ -1

FALSE . \ 0

## Fortran[edit]

Fortran started off in 1957 with only floating-point and fixed-point variables, so any calculations in the style of Boolean arithmetic would be done with integer values such as zero and not-zero, using multiplication and addition for **and** and **or**.

Fortran 66 introduced a **logical** data type which can be set to either **.true.** or **.false.** or be generated via logical expressions such as <=, etc. Such variables cannot be used in normal arithmetic with operators such as +-*/ but only with logical operators such as .OR. and so on. If via the EQUIVALENCE statement their numerical values (or, bit patterns) are inspected as say an integer, the values may well not be as anticipated and differ between computers and compilers. For instance, on the Burroughs 6700 an **integer** variable equivalenced to a **logical** variable would appear as **.true.** if odd, **.false.** if even.

TYPE MIXEDThe array STUFF might occupy 900 bytes, or, 1600 bytes if each double-precision value has to be aligned to an eight-byte boundary. In the latter case, it may be better to declare LIVE and VALUE to be separate hundred-element arrays as in

LOGICAL*1 LIVE

REAL*8 VALUE

END TYPE MIXED

TYPE(MIXED) STUFF(100)

TYPE MIXED

LOGICAL*1 LIVE(100)

REAL*8 VALUE(100)

END TYPE MIXED

TYPE(MIXED) STUFF

Except that now only hundred-element variables of type MIXED can be declared. Either way, the record size needed for a disc file holding such items will need careful thought.

## FreeBASIC[edit]

FreeBASIC has a built-in Boolean type (equivalent to a signed one byte integer) with built-in constants true and false to represent values of that type. Note also that:

- Numeric expresions can be converted to the Boolean type either implicitly or using the CBool operator - zero is converted to false and non-zero to true.

- Boolean expressions can be converted to a numeric type either implicitly or using the appropriate cast operator (CInt, CByte, CDbl etc) - false is converted to 0 and true to -1.

- String expressions such as "false" and "true" (regardless of case) can also be converted to Boolean using CBool.

- It is possible to overload CBool for user-defined types to yield a Boolean value.

Sample code:

' FB 1.05.0 Win64

Dim i As Integer = 23

Dim s As String = "False"

Dim b As Boolean

b = i

Print b

b = CBool(s)

Print b

i = b

Print i

i = CInt(true)

Print i

Sleep

- Output:

true false 0 -1

## Futhark[edit]

Futhark has a `bool`

type, with the two values `True`

and `False`

. They are used for branching.

## Gambas[edit]

**Click this link to run this code**

Public Sub Main()

Dim bX As Boolean

Print bX

bX = True

Print bX

End

Output:

False True

## GAP[edit]

1 < 2;

# true

2 < 1;

# false

# GAP has also the value fail, which cannot be used as a boolean but may be used i$

1 = fail;

# false

fail = fail;

# true

## Go[edit]

Go defines a built-in data type `bool`

, which has exactly two values, represented by the keywords `true`

and `false`

. There is no conversion between booleans and other data types. Conditionals require a boolean value, so if i is a numeric type, for example, you must spell out `if i != 0 {` if you wish to interpret it as boolean.

The template package however, uses a different rule for `if` actions. There, it is testing if a "pipeline" is "empty" where the empty values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero.

## Groovy[edit]

Groovy has a boolean "primitive" type and a Boolean "object wrapper" type directly derived from Java. See the Java solution to this task for more details.

Unlike Java, any null reference converts to a boolean "false", while any non-null object reference converts to a boolean "true"... EXCEPT if that object has a specific defined conversion to boolean "false". For example, for any numeric type, any zero value representation converts to "false" and any non-zero value converts to "true". For any collection type, non-empty converts to "true" and empty converts to "false".

## Haskell[edit]

The Haskell standard Prelude defines a data type `Bool`

, which has exactly two members:

data Bool = False | True deriving (Eq, Ord, Enum, Read, Show, Bounded)

In addition to all the functionality of any other Haskell algebraic data type (e.g. pattern matching), and the specified derived typeclass instances (e.g. `False == False`

, `succ False == True`

, `(maxBound :: Bool) == True`

, etc.), the built-in guard (“`|`

”) and `if`

syntaxes use Bool.

As with any other Haskell data type, there are no automatic conversions of other types to Bool.

## HicEst[edit]

Zero is false, non-zero is true. Numbers also work in place of boolean expressions following this rule.

## HolyC[edit]

In HolyC, there are the reserved keywords `TRUE` and `FALSE`. Variables to hold these values are declared as `Bool`.

Any value which is equal to 0 is false, while a value which is not equal to 0 is true. Relational and logical operators evaluate to 0 for false and 1 for true. Any of the following can be used:

- Any integer type, where 0 gives false, and any other value gives true.
- Any floating point type, where again, 0 gives false and everything else gives true.
- Any pointer type, where the null pointer gives false and any other pointer gives true.

## I[edit]

Any non-zero number is true in I.

software {

if true

print("this prints")

end

if 1

print("this prints")

end

if false

print("this does not print")

end

if 0

print("this does not print")

end

}

## Icon and Unicon[edit]

Icon and Unicon do not use Boolean values for flow control. Rather they use success (returning a result, any result even a null) or failure (a signal) for this purpose. Built-in controls support not, and (&), and or (|). For an example of how this works, see Short Circuit Evaluation. Icon and Unicon do support bit operations on integers which could be used to record Boolean state. See also Logical Operations for an example of how and when Boolean values might be implemented.

## Idris[edit]

Idris> :doc Bool

Data type Prelude.Bool.Bool : Type

Boolean Data Type

Constructors:

False : Bool

True : Bool

## Inform 6[edit]

Inform 6 has the constants `true`

and `false`

, which are identical to `1`

and `0`

respectively. One of these values will always be yielded by a condition operator (an operator that yields a boolean value). In addition, any non-zero value is considered to be true.

## Inform 7[edit]

The Boolean type is called "truth state" and has the values "true" and "false".

However, Inform 7 distinguishes between Boolean values and conditions. Comparison expressions do not return truth states, and truth state expressions cannot be used directly in conditional statements. There is a conversion from condition to truth state:

let B be whether or not 123 is greater than 100;

And truth states can be used in conditions by adding an explicit comparison:

if B is true, say "123 is greater than 100."

Phrases (functions) cannot be defined to return a truth state directly. Instead, they are defined using "to decide whether" (or "to decide if") and can then be used as conditions:

To decide whether the CPU is working correctly:

if 123 is greater than 100, decide yes;

otherwise decide no.

When play begins:

[convert to truth state...]

let B be whether or not the CPU is working correctly;

[...or use as a condition]

if the CPU is working correctly, say "Whew."

## J[edit]

False is `0`, true is `1`. This is an advantage.

This approach also works well with Bayes' theorem, as false matches 0% probability and true matches 100% probability.

## Java[edit]

Java has `true` and `false` keywords, representing the only values of type `boolean`. There are also object wrappers `Boolean.TRUE` and `Boolean.FALSE`, of type `Boolean` which may be un-boxed into `boolean`s (auto-unboxed in Java 1.5+). There are no automatic conversions from any other types into `boolean`, and it is a compile-time error to use any type other than `boolean` or `Boolean` in a place that expects a `boolean` (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.).

## JavaScript[edit]

The Boolean type has two values: `true`

and `false`

The following table shows the result of type conversions to boolean:

- Undefined: any undefined value is converted to
`false`

- Null:
`false`

- Number: the numbers
`0`

,`-0`

,`NaN`

are`false`

; otherwise`true`

- String: the empty (zero-length) string is
`false`

; otherwise`true`

- Object: any object is converted to
`true`

(source: ECMAScript Language Reference)

## jq[edit]

`true` and `false` are the only entities of type "boolean":

`
`

$ jq type true "boolean" false "boolean"

`
`

The above shows the jq command invocation, followed by alternating lines of input and output.

jq's logical operators, however, do not require boolean inputs. In brief, `false` and `null` are both regarded as false, and all other JSON entities are regarded as `true`. That is, all values except for `false` and `null` are truthy.

## Julia[edit]

Julia has a built-in `Bool`

type with values `true`

and `false`

.

Other objects do not represent boolean values and cannot be used in conditional expressions, for example:

julia> if 1

println("true")

end

ERROR: type: non-boolean (Int64) used in boolean context

However, integers can be converted to boolean types with the `bool()`

function (which treats nonzero values as `true`

)

julia> bool(-2:2)

5-element Bool Array:

true

true

false

true

true

## KonsolScript[edit]

The Boolean type has two values: `true`

and `false`

The following table shows the result of type conversions to boolean:

- Number: the number
`0`

is`false`

; otherwise`true`

- String: the empty (zero-length) string is
`false`

; otherwise`true`

`

## Kotlin[edit]

Booleans in Kotlin are given by the literals true and false, case sensitive, which are the only instances of the class Boolean.

## LabVIEW[edit]

This image is a VI Snippet, an executable image of LabVIEW code. The LabVIEW version is shown on the top-right hand corner. You can download it, then drag-and-drop it onto the LabVIEW block diagram from a file browser, and it will appear as runnable, editable code.

## Lasso[edit]

Comparisons are evaluated in Lasso as either true of false, so "1 == 2" will evaluate as true, and "1 == 1" will evaluate as true.

A variable can also be assigned a boolean type, and as such then holds either true of false states.

!true

// => false

not false

// => true

var(x = true)

$x // => true

$x = false

$x // => false

In a conditional, if the result is the integer 0, it is also evaluated as boolean false. If the conditional results in an integer greater than zero, it is evaluated as boolean true.

local(x = string)

// size is 0

#x->size ? 'yes' | 'no'

local(x = '123fsfsd')

// size is 8

#x->size ? 'yes' | 'no'

- Output:

no yes

## LFE[edit]

> 'true

true

> 'false

false

> (or 'false 'false)

false

> (or 'false 'true)

true

## Liberty BASIC[edit]

IF-statement, loop condition treats any non-zero integer as true. Comparison operators evaluate to 1 (true) or 0 (false).

## Lingo[edit]

Lingo has the constants TRUE and FALSE. In numerical context they have the values 1 and 0. In boolean context any nonzero integer evaluates to TRUE.

put TRUE

-- 1

put FALSE

-- 0

if 23 then put "Hello"

-- "Hello"

## Little[edit]

For conditionals, numeric variables (including poly variables with a number in them), evaluate to true or false based on their value.

Use the defined() buildin to test if a variable is defined.

For the rest of variable types the value depend if the variable is defined or not.

int a = 0;

int b = 1;

int c;

string str1 = "initialized string";

string str2; // "uninitialized string";

if (a) {puts("first test a is false");} // This should not print

if (b) {puts("second test b is true");} // This should print

if (c) {puts("third test b is false");} // This should not print

if (!defined(c)) {puts("fourth test is true");} // This should print

if (str1) {puts("fifth test str1 is true");} // This should print

if (str2) {puts("sixth test str2 is false");} // This should not print

## LiveCode[edit]

true and the string "true" are both logical true, similarly for false and "false" being logical false.

## Logo[edit]

Logo has predefined symbols for true and false (`"true`

and `"false`

), which are the values returned by predicates and required by logical operators and conditionals.

print 1 < 0 ; false

print 1 > 0 ; true

if "true [print "yes] ; yes

if not "false [print "no] ; no

Unlike other lispy languages, there are no other implicit conversions. You must test explicitly for zero or empty collections.

if equal? 0 ln 1 [print "zero]

if empty? [] [print "empty] ; empty list

if empty? "|| [print "empty] ; empty word

## Lua[edit]

All values in Lua other than `false`

or `nil`

are considered `true`

:

if 0 then print "0" end -- This prints

if "" then print"empty string" end -- This prints

if {} then print"empty table" end -- This prints

if nil then print"this won't print" end

if true then print"true" end

if false then print"false" end -- This does not print

## Maple[edit]

The keywords "true" and "false" are the default boolean values.
Expressions involving relational operators are evaluated logically using the `evalb`

command.
Expressions under assumptions may be evaluated logically using the `is`

command.
Types may be tested, resulting in boolean values, using the `type`

command.

## Mathematica[edit]

True and False are the default boolean values. To make any expression a boolean use the Boole[] function.

## MATLAB[edit]

The keywords "true" and "false" are the default boolean values. But, many functions prefer to return boolean "1" or "0" instead of "true" or "false". It is very important to note that having a function return a numerical 1 or 0 is not the same as a boolean "1" or "0". To make a number or array of numbers a boolean use the logical() function. logical() will convert any non-zero number to a boolean "1" and any zero entries a boolean "0".

Sample Usage: (islogical() is a function that returns a boolean "1" if the input is a boolean, "0" otherwise)

>> islogical(true)

ans =

1

>> islogical(false)

ans =

1

>> islogical(logical(1))

ans =

1

>> islogical(logical(0))

ans =

1

>> islogical(1)

ans =

0

>> islogical(0)

ans =

0

## Maxima[edit]

is(1 < 2);

/* true */

is(2 < 1);

/* false */

not true;

/* false */

not false;

/* true */

## Metafont[edit]

Metafont has the type `boolean`; a boolean variable can be `true` or `false`.
Using non boolean values (or expressions that do not evaluate to a boolean value) results in a recoverable error; by default, any non-boolean value is interpreted as false.

## Mirah[edit]

import java.util.ArrayList

import java.util.HashMap

# booleans

puts 'true is true' if true

puts 'false is false' if (!false)

# lists treated as booleans

x = ArrayList.new

puts "empty array is true" if x

x.add("an element")

puts "full array is true" if x

puts "isEmpty() is false" if !x.isEmpty()

# maps treated as booleans

map = HashMap.new

puts "empty map is true" if map

map.put('a', '1')

puts "full map is true" if map

puts "size() is 0 is false" if !(map.size() == 0)

# these things do not compile

# value = nil # ==> cannot assign nil to Boolean value

# puts 'nil is false' if false == nil # ==> cannot compare boolean to nil

# puts '0 is false' if (0 == false) # ==> cannot compare int to false

#puts 'TRUE is true' if TRUE # ==> TRUE does not exist

#puts 'FALSE is false' if !FALSE # ==> FALSE does not exist

## Modula-2[edit]

MODULE boo;

IMPORT InOut;

VAR result, done : BOOLEAN;

A, B : INTEGER;

BEGIN

result := (1 = 2);

result := NOT result;

done := FALSE;

REPEAT

InOut.ReadInt (A);

InOut.ReadInt (B);

done := A > B

UNTIL done

END boo.

## Modula-3[edit]

Similar to Ada, Modula-3 has a built-in `BOOLEAN` type defined as

TYPE BOOLEAN = {FALSE, TRUE}

## Monte[edit]

Much like E, Monte has built-in objects `true` and `false`, and a boolean guard.

def example(input :boolean):

if input:

return "Input was true!"

return "Input was false."

## MUMPS[edit]

M[UMPS] has no data types per se, however, any value can be coerced to a specific interpretation by applying certain operators.

Internally, the language treats any "zero" value as a "false", and any "non-zero"
value as a "true".

Values like 1, 2, 13245.08763, .1, "0.00001234ABC" and "1234ABC" are "true".

Values like 0, -3, "", " 123" (note the leading space in this one),
"+++++567", "abc", "abc1245" are "false".

When a boolean operator is applied to an operand, the value of that operand is coerced to a logical value, that is: if the value starts out with a sequence of digits that look like a non-zero number, the value is "true" (1), and otherwise that value is "false" (0).

There are two standardized binary boolean operators: & (and) and ! (or). Newer implementations of the language may also support !! (exclusve or). There is one unary boolean operator: ' (not).

## Nemerle[edit]

In Nemerle, boolean values are held in variables of type **bool**, and can be either **true** or **false**. Comparison expressions evaluate to boolean values as well.

## NetRexx[edit]

NetRexx inherits boolean functionality directly from the Java virtual machine with the exception that the `true`

and `false`

keywords are not defined to the language.
Defining `true`

and `false`

variables can lead to name collisions during compilation so a simple expedient is to define boolean functions `isTrue`

and `isFalse`

to return the appropriate values.

/* NetRexx */

options replace format comments java crossref savelog symbols nobinary

bval = [1, 0, 5, 'a', 1 == 1, 1 \= 1, isTrue, isFalse]

loop b_ = 0 for bval.length

select case bval[b_]

when isTrue then say bval[b_] 'is true'

when isFalse then say bval[b_] 'is false'

otherwise say bval[b_] 'is not boolean'

end

end b_

method isTrue public static returns boolean

return (1 == 1)

method isFalse public static returns boolean

return \isTrue

- Output:

1 is true 0 is false 5 is not boolean a is not boolean 1 is true 0 is false 1 is true 0 is false

## Nim[edit]

if true: echo "yes"

if false: echo "no"

# Other objects never represent true or false:

if 2: echo "compile error"

## Oberon-2[edit]

VAR

a,b,c: BOOLEAN;

...

a := TRUE;

b := FALSE;

c := 1 > 2;

## Objeck[edit]

Objeck has a `Bool` type that is set to either `true` or `false`. By default boolean types are initialized to `false`. The boolean type also allows methods to be invoked, which perform simple conversions or print given values.

## Objective-C[edit]

Objective-C follows pretty much the same rules as C. In addition to C, Objective-C has a `BOOL`

boolean type, with values `YES`

for true and `NO`

for false. Objective-C also adds several special types of pointers; for pointers to objects (values of type `id`

), the `nil`

pointer is false, everything else is true; for pointers to classes (values of type `Class`

), the `Nil`

pointer is false, everything else is true.

## OCaml[edit]

OCaml defines a built-in data type `bool`

, which has exactly two members, represented by the keywords `true`

and `false`

:

type bool = false | true

In addition to all the functionality of any other OCaml algebraic data type (e.g. pattern matching), and the functionality of any other OCaml data type (e.g. comparisons `false = false`

, `false < true`

, etc.), `bool`

is also used in the guards in pattern matching (“`when`

”) and `if`

and `while`

syntaxes.

As with any other OCaml data type, there are no automatic conversions of other types to `bool`

.

## Octave[edit]

Octave uses `true` (1) and `false` (0). The class of a variable holding a boolean value is *logical*, which however can be casted to a numeric class, so that `r = true; r * 2`

gives 2 as result. Any non-zero value is interpreted as true, and 0 as false.

## Oforth[edit]

Oforth uses `true` (1) and `false` (0)

Any non-zero value is interpreted as true, and 0 as false.

## Ol[edit]

**#true** is True, **#false** is False; **#t** is synonym for #true, **#f** is synonym for #false.

In conditionals everything that is not #false is True.

p.s. Empty lists - '() - in conditionals is True.

## ooRexx[edit]

`.true` or `1` are true, `.false` or `0` are false

## Order[edit]

Order supplies the keywords `8true`

and `8false`

. Other types are not supposed to automatically convert to any boolean value (in practice some may do so due to implementation quirks, but this is not reliable).

## Oz[edit]

`true` and `false` are the only boolean values. No other values are automatically converted to bool.

## PARI/GP[edit]

Generally, false is 0 and true is nonzero. Certain other values also behave as false, like the vector [0]. Built-in boolean functions use 0 and 1 (but note that some functions like `ispower`

are not boolean!).

The details of what is considered true or false is contained in see the function `gequal0`:

- An integer (t_INT), polynomial (t_POL), power series (t_SER), or element of a finite field (t_FFELT) is false if and only if it is 0.
- A real number (t_REAL) or complex number (t_COMPLEX) is false if and only if its absolute value rounds to 0 at the object's precision. Note that this can make nonzero complex numbers (with tiny norm) false.
- An integer mod m (t_INTMOD) is false if and only if its residue class is 0, i.e., if
`lift(x)`

is 0. - A
*p*-adic number (t_PADIC) is false if and only if it is zero up to the object's*p*-adic precision is 0, i.e., if`lift(x)`

is 0. - A vector (t_VEC), column vector (t_COL), or matrix (t_MAT) is false if and only if all of its components are 0. Note that
`[]`

is thus false. - t_QUAD, t_POLMOD, t_RFRAC

## Pascal[edit]

In all flavors of pascal there is no such foolishness as numbers of empty strings or pointers ( initialized or otherwise ) being evaluated as boolean. There is the boolean type as defined by the RTL statements such as:

var

pInt : ^integer ;

ValidP : boolean ;

if pInt then ...

or

if pInt^ then ...

Will always be a syntax error. The following correct evaluations of variables are allowed:

if not(pInt = nil) then ValidP := true ;

or

if ( ValidP ) and (pInt^ <> 0) then ...

## Perl[edit]

my $x = 0.0;

my $true_or_false = $x ? 'true' : 'false'; # false

or

my $x = 1; # true

my $true_or_false;

if ($x) {

$true_or_false = 'true';

}

else {

$true_or_false = 'false';

}

The values in Perl that are false are: `0` (as a number (including `0.0`), or as the string `'0'`, but **not** the string `'0.0'`), the empty string `''`, the empty list `()`, and `undef`. Everything else is true. See perlsyn.

### Short circuit evaluations[edit]

Boolean comparison of zero against itself gives a value of one, but Perl uses short circuit evaluations, so any true or false value may be returned from a boolean expression:

print (7 && 2); # 2, rather than 1(true)

print (2 && 7); # 7, rather than 1(true)

print (7 xor 2); # empty string, rather than 0(false)

print ('apples' && 'pears'); # pears, rather than 1(true)

print ('apples' xor 'pears'); # empty string, rather than 0(false)

### Objects[edit]

Objects may break these rules at will via overloading.

### There are no keywords for true and false[edit]

Perl has no builtin "true" or "false" keywords. This is a caveat, because true and false are bareword strings and evaluate to true:

# This does not work

# true and false are not special so will be treated as bareword strings

if (true) { print "true is true\n" }; # This prints

if (false) { print "false is true\n" }; # So does this

if (spongebob) { print "spongebob is true\n" }; # A bareword string

### Special cases[edit]

As a special case, literal `1`s and `0`s will never cause a "Useless use of a constant in void context" warning. Another special case worth pointing out here is that the string `'0 but true'` won't provoke a warning if it's used as a number.

## Perl 6[edit]

Perl 6 provides an enumeration `Bool`

with two values, `True`

and `False`

. Values of enumerations can be used as ordinary values or as mixins:

my Bool $crashed = False;

my $val = 0 but True;

For a discussion of Boolean context (i.e. how Perl decides whether something is true or false), see Synopsis 2.

## Phix[edit]

Zero is false, any other number is true. Attempting to use a string or sequence as a boolean is assumed to be a programming logic blunder and causes a fatal run-time error.

Conditions such as `if length(s) then`

are permitted, but the more explicit `if length(s)!=0 then`

is preferred. Comparison operators evaluate to 1(true) or 0(false).
A boolean test is inverted by preceding it with the keyword `not`

. The null character ('\0') is considered false, all other characters are deemed true.
The builtin constants TRUE/FALSE and their aliases True/true/False/false may also be used.

## PHP[edit]

The values in PHP that are false are: `FALSE`, `NULL`, the number `0` (as an integer `0`, float `0.0`, or string `'0'`, but **not** the string `"0.0"`), the empty string `""`, the empty array `array()`, and "SimpleXML objects created from empty tags"(?).

Everything else is true. The keyword `TRUE` exists.
[1]

## PicoLisp[edit]

Like in all Lisps, the symbol 'NIL' denotes "false", any other value "true". PicoLisp also uses NIL as the empty list, so the empty list is false.

Some functions return the symbol 'T' for "true" if no other useful (non-NIL) value is available in the given context. Note that 'NIL' and 'T' are written in uppercase letters (PicoLisp is case-sensitive).

## Pike[edit]

> 0;

(3) Result: 0

> false;

(4) Result: 0

> 0;

(6) Result: 0

> !true;

(7) Result: 0

> true;

(8) Result: 1

> 1;

(9) Result: 1

>

## PL/I[edit]

True is `'1'b`

and false is `'0'b`

.

Declare x bit(1);

x='1'b; /* True */

x='0'b; /* False */

Using the macro facility one can define reasonable symbols for true and false

*process source attributes xref macro or(!);

tf: proc options(main);

%Dcl true char; %true='''1''b';

%Dcl false char; %false='''0''b';

If true Then

Put Skip list('That''s true');

If false Then

Put Skip List('ERROR');

Else

Put Skip List('false was recognized');

End;

- Output:

That's true false was recognized

## Pony[edit]

Boolean values are `true`

and `false`

. Conditions must have type Bool, i.e. they are always true or false.

## PowerBASIC[edit]

In addition to what's noted above under BASIC, PowerBASIC for Windows and PowerBASIC Console Compiler have the `ISTRUE`

and `ISFALSE`

functions. According to the help file, they "return the logical truth or falsity of a given expression". (PowerBASIC lacks a boolean data type, so the usual practice is to use integers in PB/DOS, and longs in PB/CC and PB/Win.)

DIM x AS LONG

x = ISTRUE(1 = 1) ' returns -1

x = ISTRUE(1 = 0) ' returns 0

x = ISFALSE(1 = 1) ' returns 0

x = ISFALSE(1 = 0) ' returns -1

## PostScript[edit]

Predefined constants are:

true

false

## PowerShell[edit]

Two automatic variables exist for this purpose:

$true

$false

However, nearly everything can be converted to a boolean value, as detailed in the following list:

- any non-zero number evaluates to
**true**, zero evaluates to**false** - any non-empty string evaluates to
**true**, an empty string evaluates to**false** - an empty array evaluates to
**false** - an array containing exactly one item evaluates to whatever the only item evaluates to
- any array with more than one item evaluates to
**true** - a reference to any object evaluates to
**true**,`$null`

evaluates to**false**

## PureBasic[edit]

PureBasic does not have a Boolean variable type. An integer type is typically used instead. Boolean values are only supported as part of a loop's condition (While/Wend, Repeat/Until) or in a conditional (If/Endif). In these cases if the result of a variable or a numeric expression is zero it is evaluated as False, otherwise it is evaluated as True. A string variable assigned a null string would be evaluated as False.

## Python[edit]

Python has a boolean data type with the only two possible values denoted by `True`

and `False`

.

The boolean type is a member of the numeric family of types (specifically a subclass of `int`

), and when used in a numeric, but not boolean context, `True`

has the value one and `False`

the value zero. Also `hash(True) == hash(1)`

and same goes for `False`

and `0`

. Conversely, when numbers are used in a boolean context, zero is false and anything other than zero is true. (Note however, that `True`

is equal to `1`

, so for example `True + True != True`

.)

In a boolean context, Python extends what is meant by true and false by accepting empty collection types, such as an empty dict or an empty list as being False, and non-empty collection types as being True, so in an if statement one might branch on a list which would be the same as testing if the list had any contents.

In Python 2, a user-created class that defines a `__nonzero__` method to return False or 0, or whose `__len__` method returns 0, will be treated as `False`

, otherwise the instance is treated as `True`

. In Python 3, the magic method `__nonzero__` has been changed to `__bool__`, which can only return values of type `bool` (not even `int` or `None`).

`None`

is also `False`

in a boolean context.

**Some examples:**

>>> True

True

>>> not True

False

>>> # As numbers

>>> False + 0

0

>>> True + 0

1

>>> False + 0j

0j

>>> True * 3.141

3.141

>>> # Numbers as booleans

>>> not 0

True

>>> not not 0

False

>>> not 1234

False

>>> bool(0.0)

False

>>> bool(0j)

False

>>> bool(1+2j)

True

>>> # Collections as booleans

>>> bool([])

False

>>> bool([None])

True

>>> 'I contain something' if (None,) else 'I am empty'

'I contain something'

>>> bool({})

False

>>> bool("")

False

>>> bool("False")

True

## R[edit]

Similarly to Octave, R uses `TRUE` and `FALSE`, kept in variable of class logical, which is silently casted to 1 (TRUE) or 0 (FALSE) if used as numeric value. The opposite is also true: the value 0 can be used as FALSE, and non-zero numbers as TRUE.

The values T and F are given the values TRUE and FALSE respectively (for compatibility with S-Plus), though these may be changed to other values by the user.

## Racket[edit]

Racket has the standard Scheme Boolean values `#t` and `#f`, and will also accept `#true` and `#false`. This is a literal syntax, so it can be used anywhere including in quoted positions. There are also bindings for `true` and `false` (but of course when these are quoted, the result is plain symbols). Like other Scheme descendants, many conditional constructs treat any non-false value as "truthy." So, for instance,

(cond ([(< 4 3) 'apple]

['bloggle 'pear]

[else 'nectarine])

... evaluates to `'pear`, because `'bloggle` is not false.

## Raven[edit]

Raven considers 0 as `FALSE`

, -1 as `TRUE`

TRUE print

FALSE print

2 1 > print # TRUE (-1)

3 2 < print # FALSE (0)

42 FALSE != # TRUE (-1)

## REBOL[edit]

REBOL uses values of type **logic!** to represent boolean values. A boolean value can be 'true' or 'false', which also happen to be understood as predefined constants. Other constants are also provided to improve program readability:

True | False |
---|---|

true | false |

yes | no |

on | off |

any [block! series! date! number! string! ...] | none |

As the last true value implies, pretty much any other type will evaluate to true. This is important to remember if you're used to a language where the value "0" is considered to be false -- in REBOL, it's true.

## Retro[edit]

Zero is false and non-zero is true. Comparison functions return **-1** for true and **0** for false.

## REXX[edit]

The REXX language enforces the values for *true* and *false*, only the two values are valid:

- 0 (zero) [for false]
- 1 (one) [for true]

The following aren't **true** or **false**:

- 0.
- 0.0
- 00
- 1.
- 1.0
- 001
- +1
- 2
- (a null value, that is, length=0)
- any value with a blank before/in/after the value.

### simplistic[edit]

true = 1

false = 0

### spruced up[edit]

Some programmers like to "spruce up" such a simple assignment:

true = (1=1)

false = (1=0)

### more exactitudeness[edit]

true = (1==1)

false = (1==0)

### oblique[edit]

true = (1==1)

false = \true

[The parentheses aren't necessary in all of the above versions.]

Some REXX interpreters allow the *NOT* (`¬`

) character for negation:

false = ¬true

### esoteric[edit]

true = 1984 = 1984

false = 'war' = 'peace'

false = 'freedom' = 'slavery'

false = 'ignorance' = 'strength'

Of course, in Orwellian terms, the above **false** statements are **true**, but REXX isn't an Eric Arthur Blair reader.

## Ring[edit]

x = True

y = False

see "x and y : " + (x and y) + nl

see "x or y : " + (x or y) + nl

see "not x : " + (not x) + nl

## Ruby[edit]

The only values in Ruby that are false are: `false`

and `nil`

. They have synonyms `FALSE`

and `NIL`

.

Everything else is true. Constants `true`

(and `TRUE`

) exist. Note for Python and Perl users: unlike Python, in Ruby, the number `0`

, the empty string, the empty array, and the empty hash, etc. are all true; you can instead use the `zero?`

method to test for 0, and the `.empty?`

method to test for an empty sequence.

`false`

, `nil`

and `true`

are singleton instances of classes `FalseClass`

, `NilClass`

and `TrueClass`

respectively.
[2]

## Run BASIC[edit]

Basically 0 is false and 1 is true

if 1 then print "1 is true"

if not(0) then print "0 is false"

if 1 < 2 then print "1 < 2 TRUE"

if 2 > 1 then print "2 > 1 TRUE"

if not(2 < 1) then print "2 not < 1"

if not(1 = 0) then print "1 not = 0"

## Rust[edit]

Booleans are expressed using the `bool`

type and the two literals `true`

and `false`

.
The compiler prevents any other values from being assigned to a bool variable.
This behavior is not guaranteed inside blocks labeled as unsafe, where it is the programmers responsibility to ensure this behavior.

## Sather[edit]

The BOOL type can be `true`

or `false`

. Sather never implicitly does casting of a type in another, so numeric value or other types cannot be used (implicitly) as boolean value; nonetheless an explicit "cast" can be done:

v:BOOL := true; -- ok

i:INT := 1;

v := 1; -- wrong

if i then ... end; -- wrong: if requires a bool!

-- BUT

v := 1.bool; -- ok

if i.bool then ... end; -- ok

In this case, `0.bool`

is false, and `n.bool`

with n not equal to 0 is true.

## Scala[edit]

Booleans in Scala are given by the literals `true`

and `false`

, case sensitive, which are the only instances of the class `Boolean`

.

## Scheme[edit]

The only value in Scheme that is false is `#f`.

Everything else (including the empty list, unlike Lisp) is true. The constant `#t` represents the canonical true value.

## Seed7[edit]

Seed7 defines the type `boolean`. The only values of `boolean` are `TRUE` and `FALSE`. There are no automatic conversions from any other types into `boolean`, and it is a compile-time error to use any type other than `boolean` in a place that expects a `boolean` (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.).

## Self[edit]

Self has two objects, *true* and *false*.

## Sidef[edit]

Sidef defines the *true* and *false* boolean values, which are part of the *Bool* type.

var t = true;

var f = false;

In conditional expressions, anything that evaluates to zero or nothing is considered *false*, including empty arrays and empty hashes.

if (0 || "0" || false || nil || "" || [] || :()) {

say "true"

} else {

say "false";

}

- Output:

false

## Slate[edit]

Use `True` or `False`.

## Smalltalk[edit]

Smalltalk uses the Boolean class, which has two subclasses (True and False). `true` and `false` are singleton instances of those classes. E.g. an expression like `5 = 5` returns `true`.

## smart BASIC[edit]

- IF/THEN statements treat any non-zero value as true and zero as false.
- Comparison operators DO NOT calculate in smart BASIC. For example, PRINT (1 > 4) WILL NOT evaluate to produce a zero value (0) indicating a false condition. It will produce an error. All Boolean evaluations in smart BASIC must be determined within IF/THEN statements.

## SNUSP[edit]

Zero is false and non-zero is true, as used by the sole skip-if-zero operator (**?**).

$!/?\=false= + =true=#

\-/

## SPL[edit]

In SPL zero is false, any other value is true.

## Standard ML[edit]

Standard ML defines a top-level data type `bool`

, which has exactly two members, `true`

and `false`

:

datatype bool = false | true

In addition to all the functionality of any other Standard ML algebraic data type (e.g. pattern matching, equality `false = false`

), `bool`

is also used in `if`

and `while`

syntaxes.

As with any other Standard ML data type, there are no automatic conversions of other types to bool.

## Stata[edit]

Stata uses the values 0 for "false" and 1 for "true". In expressions involving boolean operators, any nonzero numeric value (including missing values) is considered true.

## Swift[edit]

Swift defines a built-in data type `Bool`

, which has two values, represented by the keywords `true`

and `false`

. There is no conversion between booleans and other data types. Conditionals require a type that conforms to the `BooleanType`

protocol, which provides a conversion to `Bool`

for that type; types that conform include `Bool`

and some other types.

## Tcl[edit]

- True values
`1`(or other non-zero number, e.g.,`42`)`, true, yes, on`- False values
`0`(or other zero number, e.g.,`0.0`)`, false, no, off`

Any of these values may be abbreviated, and mixed-case spellings are also acceptable. [3] Any other value gives an error. In an interactive tclsh session:

% if {""} then {puts true} else {puts false}

expected boolean value but got ""

Test for the boolean value of a string can be stuff like

if {[string is false -strict $string]} ...

which will test for "no" or "NO" or "0" or "False" or ...

## TI-89 BASIC[edit]

There are boolean literals `true`

and `false`

. No other values may be used where a boolean is expected.

## Trith[edit]

The boolean constants are *true* and *false*. In a conditional context, the only false values are *false* and *nil* -- every other value is true.

## uBasic/4tH[edit]

In conditionals, zero is false, non-zero is true. Note that **=** is not only used for assignment, it is also a fully qualified logical operator, so it is easy to assign a true boolean to a variable.

t = 1 = 1

f = 0 = 1

Print "False = ";f;", True = ";t

- Output:

False = 0, True = 1 0 OK, 0:52

## UNIX Shell[edit]

The traditional Bourne shell does not provide a reserved keyword for true or false.

Truth is determined by exit codes rather than values

The evaluation of true and false within the shell is different to the evaluation of truth from within a high level language. Within the shell, a truth is based on the exitcode of the last command in the evaluation block:

- An exitcode of zero is considered to be a true condition
- An exitcode of nonzero is considered to be a false condition

In the following example, after running the test command, the then syntactical component runs the optional branch if an exitcode is of zero determined:

if

echo 'Looking for file' # This is the evaluation block

test -e foobar.fil # The exit code from this statement determines whether the branch runs

then

echo 'The file exists' # This is the optional branch

echo 'I am going to delete it'

rm foobar.fil

fi

In some later shells, the values *true* and *false* are defined, respectively, as a return code of 0 and a return code of greater-than zero. While there are built-in functions for each of these values, booleans are most commonly the result of a test or a process termination.

true && echo "true" || echo "false"

## Ursa[edit]

Ursa has the boolean data type which can be declared using the declare (or decl) function.

decl boolean bool

Boolean values can be set to either true or false, or the result of an expression.

set bool true

# same as

set bool (= 2 2)

or

set bool false

# same as

set bool (not (= 2 2))

## Visual Basic[edit]

VB has the `Boolean`

data type and the constants `True`

and `False`

, in addition to what's listed under BASIC, above. When used outside of a boolean context, `True`

and `False`

return values depending on their context -- `-1`

and `0`

in a numeric context, `"True"`

and `"False"`

if used as strings.

Dim x As Boolean

x = IIf(Int(Rnd * 2), True, False)

MsgBox x

## Vim Script[edit]

A non-zero `Number`

is true, 0 is false.

Since a `String`

is converted automatically to a `Number`

when necessary, the following will print "false" because "foo" is converted to 0:

if "foo"

echo "true"

else

echo "false"

endif

## XLISP[edit]

Boolean "false" may be represented by `#F`, `#!FALSE`, `NIL`, or the empty list; any other value is counted as true in conditional expressions, but it is also possible to represent the Boolean value "true" using your choice of the symbols `#T`, `#!TRUE`, and `T`. All these symbols are case-insensitive. Note that `T`, unlike the others, is a variable: it is bound by default to the constant `#T`, but you can (although you shouldn't) assign it any other value including "false" (by doing something like `(setq t nil)`). Boolean values are printed as `#T` and `()`.

## XPL0[edit]

An integer value equal to 0 is false, and a value not equal to 0 is true. Relational operations evaluate to 0 for false and -1 for true. The command word 'true' equals -1, and 'false' equals 0.

## XSLT[edit]

<xsl:if test="true() or false()">

True and false are returned by built-in XPath functions.

</xsl:if>

<xsl:if test="@myAttribute='true'">

Node attributes set to "true" or "false" are just strings. Use string comparison to convert them to booleans.

</xsl:if>

<xsl:if test="@myAttribute or not($nodeSet)">

Test an attribute for its presence (empty or not), or whether a node set is empty.

</xsl:if>

## zkl[edit]

a:=True;

b:=False;

True.dir();

- Output:

True : Bool Methods: -- BaseClass Method Property __sGet __sSet copy create dir fp fp1 fp2 fpM fpN isChildOf isInstanceOf isType len method noop print println property resolve toBool toData toFloat toInt toList toString toType Properties: -- createReturnsSelf fullName id isContainer isThreadSafe itype methods name numObjects oID otype properties size type typeID vaultPath

- Programming Tasks
- Basic language learning
- Simple
- 360 Assembly
- 8051 Assembly
- 8th
- ACL2
- Ada
- ALGOL 68
- ALGOL W
- AppleScript
- Applesoft BASIC
- AutoHotkey
- AWK
- Axe
- BASIC
- BaCon
- BASIC256
- BBC BASIC
- Bc
- Befunge
- Bracmat
- Brainf***
- C
- C++
- C sharp
- Clean
- Clojure
- CMake
- COBOL
- CoffeeScript
- Common Lisp
- Component Pascal
- D
- Delphi
- Déjà Vu
- DWScript
- Dylan
- E
- EchoLisp
- EGL
- Elena
- Elixir
- Elm
- Emacs Lisp
- Erlang
- Excel
- F Sharp
- Factor
- FALSE
- Fantom
- Forth
- Fortran
- FreeBASIC
- Futhark
- Gambas
- GAP
- Go
- Groovy
- Haskell
- HicEst
- HolyC
- I
- Icon
- Unicon
- Idris
- Inform 6
- Inform 7
- J
- Java
- JavaScript
- Jq
- Julia
- KonsolScript
- Kotlin
- LabVIEW
- Lasso
- LFE
- Liberty BASIC
- Lingo
- Little
- LiveCode
- Logo
- Lua
- Maple
- Mathematica
- MATLAB
- Maxima
- Metafont
- Mirah
- Modula-2
- Modula-3
- Monte
- MUMPS
- Nemerle
- NetRexx
- Nim
- Oberon-2
- Objeck
- Objective-C
- OCaml
- Octave
- Oforth
- Ol
- OoRexx
- Order
- Oz
- PARI/GP
- Pascal
- Perl
- Perl 6
- Phix
- PHP
- PicoLisp
- Pike
- PL/I
- Pony
- PowerBASIC
- PostScript
- PowerShell
- PureBasic
- Python
- R
- Racket
- Raven
- REBOL
- Retro
- REXX
- Ring
- Ruby
- Run BASIC
- Rust
- Sather
- Scala
- Scheme
- Seed7
- Self
- Sidef
- Slate
- Smalltalk
- Smart BASIC
- SNUSP
- SPL
- Standard ML
- Stata
- Swift
- Tcl
- TI-89 BASIC
- Trith
- UBasic/4tH
- UNIX Shell
- Ursa
- Visual Basic
- Vim Script
- XLISP
- XPL0
- XSLT
- Zkl
- ML/I/Omit