Boolean Logic in Conditions?

I keep finding myself trying to do conditionals like

(n > a AND n < b) OR (n > y AND n < z)

as

...which, unsurprisingly, doesn't work.

Am I missing a trick? Example of where this would be useful here.

You can do it with ternaries (ignore the colours, I didn't define the variables)

....but that feels clunky (and leaves me scratching my head when I look at it the next day!).

Proper ternaries example -- change Local_test, as it stands values of 2 or 6 are true while all others false:

Boolean Test.kmmacros (4.0 KB)

Image

And (and this is where my head explodes), nested ternaries for when you want "3 truths", such as

"n is greater than a, less than b, and an even number"

where you can use

n > a ? (n < b ? n MOD 2 = 0 : 0) : 0

In this example, testing "in one range and even or another range and odd", Local_test of either 2 or 9 is true while other values are false:

Boolean Test Nested.kmmacros (4.1 KB)

Image

1 Like