PxPlus User Forum

Main Board => Discussions => Language => Topic started by: James Zukowski on September 11, 2019, 11:51:26 AM

Title: Compound IF expressions
Post by: James Zukowski on September 11, 2019, 11:51:26 AM
Using AND and OR in IF conditions seem to throw Syntax Errors (#20) in certain situations, e.g.,

if A$ and Anything_Else then print "OK"

Evidently, the string expression without a relational operator and comparison value has to be stand-alone:

if A$ then if Anything_Else then print "OK"

Does anyone know if this is the correct operation, or if both of these should work...?

Thanks, all!
Title: Re: Compound IF expressions
Post by: Frank Dreßler on October 04, 2019, 12:59:40 PM
The and operator is defined for numeric operands only. That is why x$ and y is an invalid expression. It's an operator like any other: You can write something like result = x and y. If the condition expression in an if statement is a string, it behaves like if not(nul(x$)) ... So to get the same effect like if x$ if y ... you can write if not(nul(x$)) and y .... You could also write if len(b$) and y or if b$<>"" and y but that's only checking for the empty string. if x$ also considers space-only strings false. It is also important to note that not(...) does only negate the boolean value of its parameter if it is numeric. When a string is passed to not(...) it inverts all bits. This means if x$ is not the inverse of if not(x$). So when using strings in a compound if expressions, you usually want to use nul(x$) or not(nul(x$)).