Nicola Sartore · Jun 21, 2022

Inline IF and assignment

I'd like to to assign a value to a variable, depending on the results of a condition. The equivalent of what can be done in c++ with the following:

(a>b) ? a=1:a=0;

Or in python:

a = 1 if a>b else 0

This makes the code much more readable and compact.

In objectscript it would be:

if (a>b){
} else{
Product version: IRIS 2021.1
0 220
Discussion (4)2
Log in or sign up to continue

One option is $select:

    set a=$select(a>b:1,1:0)

You could could also put the if..else on a single line:

    if (a<b) { set a=1 } else { set a=0 }

This would also achieve the same result, but is a bit more limited:

    set a=(a>b)

I guess $select is the best way to do it in Objectscript. It's not as intuitive as the other languages, but still it keep it simple and concise.


Hi, Nicola

I think best option is $Select as Jolyon write, but you have this option too

set a=0 set:(a>b) a=1