# Booleans [AX 2012]

*
Updated: September 21, 2011*

*
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012*

The boolean data type contains a value that evaluates to either true or false. You can use the X++ reserved literals true and false where ever a Boolean expression is expected.

Boolean expressions are also named logical expressions.

In X++ the internal representation of a boolean is an integer. You can assign any integer value to a variable declared of type boolean. The integer value 0 (zero) evaluates to false, and all others evaluate to true.

The X++ literal false is the integer value 0, and true is 1.

The following table lists several expressions and indicates whether they evaluate to true or false.

Expression |
Boolean value |
---|---|

1 |
True |

44 |
True |

true |
True |

(false == 0) |
True |

(true == 1) |
True |

(true == 8) |
False |

false |
False |

0 |
False |

Boolean declaration |
= |
boolean variable { , variable } ; |

variable |
= |
identifier [ option ] |

option |
= |
Arrayoptions | initialization |

// Simple declaration of a boolean variable, b boolean b; // Multiple declaration boolean b1,b2; // Boolean variable is initialized to true boolean b3 = true; // Declares a dynamic array of Booleans boolean b4[];

You usually use Booleans in conditional statements, or as parts or results of logical expressions. The following example shows both.

void main() { //Declares a boolean called exprValue boolean exprValue; //Assigns ExprValue the truth value of (7*6 == 42) exprValue = (7*6 == 42); ; if (exprValue) { print "OK"; } }

Here, the variable exprValue contains the value true, because 7*6 is equal to 42; so, the expression is true. The conditional statement is true; the word "OK" is displayed on the screen.

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.