Is there any way to do ternary expression?

About Monkey 2 Forums Monkey 2 Programming Help Is there any way to do ternary expression?

This topic contains 4 replies, has 2 voices, and was last updated by  impixi 2 years, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6372

    cocon
    Participant

    I don’t know if “ternary operators” exist in Monkey, but you get the idea, to do boolean check and assignment in one line. I don’t know if I remember correctly, that in MonkeyX this feature was supported.

    Other alternative way I found is this, which adds some unnecessary complexity.

    #6391

    impixi
    Participant
    [/crayon]
    #6404

    cocon
    Participant

    Superb!

    How this actually is called in Monkey? Ternary?

    #6517

    cocon
    Participant

    From what I see it’s called an “If Expression”

    #6519

    impixi
    Participant

    I’m not sure what’s going on behind the scenes, but I’d call it a “ternary operation” because it takes three elements and behaves like an operator.

    Monkey 2’s
    ? Else
    is basically equivalent to C’s
    ? :

    https://en.wikipedia.org/wiki/Ternary_operation

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.