Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Inline IF and assignment

Question
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){
    a=1
} else{
    a=0
}
#ObjectScript #InterSystems IRIS #InterSystems IRIS for Health
Product version: IRIS 2021.1

Source URL:https://community.intersystems.com/post/inline-if-and-assignment