Expression Comparisons

In Python you can say:

if 2 < 3 < 4:
print ‘Hello’

and it will be very clear and it will work.

In expression language if you say:
if( 2 < 3 < 4, ‘Hello’, ‘Goodbye’)

it will give you an error because it can’t compare three values like that.

The best way around this I have found is:
if( 2 < 3 && 3 < 4, ‘Hello’, ‘Goodbye’)

but in practice and for longer comparisons it quickly becomes less clear than the Python version.

if( myVal1 < myVal2 && myVal2 < myVal3 && myVal3 < myVal4, ‘Hello’, ‘Goodbye’)

Is there another way to do this or has Python spoiled me?

Any ideas are appreciated.


  • Mike

Python has spoiled you. :laughing:

I’ve never used it before but I believe the switch function will handle multiple evaluations and returns.

If you really must, you can do this with python via objectScript() or the latest runScript():objectScript('args[0] < args[1] < args[2]', {Root Container.property1}, {Root Container.property2}, {Root Container.property3})Though I doubt I’d actually do this unless one or more of the arguments had execution side effects or big delays.
{ /end shameless plug for one of my modules :laughing: }