Conditional statements in xtend ( (a == b)? 1 : 2

Hi,

I want to do the following:

val boolean isday = ( Time_Hour < start_morning || Time_Hour >= start_night) ? 0 : 1

This works fine in C++, but what is the XTend equivalent?

In terms of language (ignoring whether your other variables exist), you would want to use true instead of 1 and false instead of 0. Or

var boolean isday = Time_Hour >= start_morning && Time_Hour < start_night

(Not tested.)

Hi watou,

thank you for your reply. I was tired yesterday so I mixed up the variable types.
You’re right, this can’t work with boolean type.
I wanted to do something like this:

val int bla = (Time_Hour >= start_morning) ? 1 : 88

but this doesn’t work, too. :frowning:

val int bla = if (Time_Hour >= start_morning) 1 else 88
1 Like

almost three years later: thanks! I just wanted to create a topic about shorthand variable assignments with Boolean logic. your post spared the community of that post :slight_smile: