Purpose |
Return the logical truth or falsity of a given expression. | ||||||||||||||||||

Syntax |
ISFALSE ISTRUE | ||||||||||||||||||

Remarks |
ISTRUE returns -1 (TRUE) when expr evaluates as non-zero; otherwise, it returns zero (FALSE). ISFALSE returns -1 when expr evaluates as 0 (FALSE); otherwise, it returns zero.
PowerBASIC's NOT
operator serves a double duty: it returns the one's-complement of
an
test1 = 0 ' test1 is FALSE (zero) IF NOT test1 THEN ' TRUE (-1 is non-zero) [
test2 = 1 ' test2 is TRUE (1 is non-zero) IF NOT test2 THEN ' still TRUE (-2 is non-zero) [ In this case, NOT does not reverse the TRUE/FALSE
value of test2. ISFALSE ensures that the test is performed
exactly as you would expect: IF ISFALSE test2 THEN ' ISFALSE detects test2 is [ This problem does not exist when you're testing
for logical truth. PowerBASIC considers that an expression is TRUE
in every case | ||||||||||||||||||

Restrictions |
ISTRUE and ISFALSE operators evaluate the "whole" expression following the keyword, subject to their Operator Precedence level. For example, parentheses contained within the expression are regarded as an integral part of the expression, and do not act as delimiters for the ISTRUE and ISFALSE operators. With this in mind, combining a logical test result into a further expression means that the expressions must be separated to ensure the correct evaluation. Consider the following statement: IF ISTRUE (x&) + y& THEN PowerBASIC evaluates the entire expression IF ISTRUE (x& + 2) THEN or it could be simplified even further: IF ISTRUE x& + 2 THEN If you wish to utilize the numeric result of the logical test in a further expression, parentheses must be added to separate the expressions correctly: IF (ISTRUE x&) + 2 THEN | ||||||||||||||||||

See also |