BOOLEAN Expressions and if Statements
- Last UpdatedOct 24, 2022
- 2 minute read
New expressions based on the operators such as EQ and GT give a BOOLEAN result that can be used directly in a PML 2 if test:
if (!NewValue - 1 GT 0) then
The expression can be a simple variable provided it is a BOOLEAN type variable:
!Success = !NewValue GT 0
if (!Success) then
The expression could be a User-defined PML function provided it returns a BOOLEAN result:
if (!!MyFunction() ) then
Note:
The BOOLEAN constants TRUE, FALSE, YES and NO and their single-letter abbreviations not enclosed in quotes return BOOLEAN results and so can be used directly in expressions. For example:
|
Code |
Result Type |
|
if ( TRUE ) if ( FALSE ) |
BOOLEAN |
|
if ( T ) if ( F ) |
BOOLEAN |
|
if ( YES ) if ( NO ) |
BOOLEAN |
|
if ( Y ) |
BOOLEAN |
The following do not return BOOLEAN values and are therefore invalid:
|
Code |
Result Type |
|
if ( 1 ) if ( 0 ) |
REAL |
|
if ( 'TRUE' ) if ( 'FALSE' ) |
STRING |
|
if ( 'T' ) if ( 'F' ) |
STRING |
|
Variable = 1 if ($Variable) |
REAL |
For upward compatibility with PML 1, STRING variables set to TRUE, FALSE, YES, or NO or their single-letter abbreviations can be used in an if-test as long as they are evaluated with a preceding $. For example:
|
Code |
Result Type |
|
Variable = 'TRUE' if ($Variable) |
STRING |
There is a built-in PML method and a function for converting a value to BOOLEAN:
!MyString = ‘TRUE’
if (!MyString.Boolean() ) then . . .
The BOOLEAN conversion is as follows:
|
Code |
Result |
|
REAL zero |
FALSE |
|
$* All other positive and |
TRUE |
|
STRING FALSE, F, NO and N |
FALSE |
|
STRING false, f, no and n |
FALSE |
|
STRING TRUE, T, YES AND Y |
TRUE |
|
STRING true, t, yes and y |
TRUE |