Does Xojo offer an inline if statement?

Does Xojo offered an inline version of the if() statement, something like the following?

if is_offered then (return true ; else return false)

I know that one currently has to write it like the following:

if is_offered then
     return true
     return false
end if

you can use if as function like this:

return if(is_offered, true, false)

or better just

return is_offered


Thank you! That’s much simpler… :slight_smile:


You can also write it as:

if is_offered Then Return True Else Return False

1 Like

The correct link is to If (as a trinary operator):

This code outputs “Big number”:

Var myInteger As Integer = 42
MessageBox( If myInteger > 40, "Big number", "Small number")
1 Like

If you’re using the trinary operator, yes. But the form I gave is also correct.

But he asked specifically for an inline form of if - so your answer was “correct”, but not the answer to the question :wink:

bracket in the wrong spot:

Var myInteger As Integer = 42
MessageBox If (myInteger > 40, "Big number", "Small number")

(Thanks to Norman for spotting it)

1 Like

While I knew about the inline “if” syntax and use it a lot, I didn’t know the “Else” keyword worked in this case. Amazing to still learn things this way (i.e. from someone else’s question in the forum) instead of everyday’s use of the IDE (and it’s not the first nor last time).
Thanks for sharing.

Yes - oddly, I didn’t know about the Else part either so the OP has done us both a favour. :smiley:

There’s also a keyboard shortcut to have the IDE rewrite the one line if-then-else onto separate lines, to assist debugging. But I can’t remember what it is. :dizzy_face:

Glad users ask enough questions in this forum. Best way to learn for us, accustomed users :wink:

Just tried in live: it’s shift+return.

1 Like