NEWTON

NEWTON


Popular tags

    Does Cairo Lang have any logic operators?

    Asked

    6 months ago

    79

    views


    0

    I'm very curious: does Cairo have any logic operators? I found bitwise_or bitwise_and etc. but it is not wokring if I want to do something like

    if (x == y) OR (x == -y) { ... }

    This question was originally posted on StarkNet Discord

      cairo-beginners mathdiscordcairo

    Newton

    asked

    6 months ago


    1 answers

    0

    Accepted answer

    Only and is currently supported in if-statements. If you want to get or then in this case you can do

    if ((x - y) * (x + y) == 0) {...}
    

    Then, if x == y then the first factor will be zero (and therefore the entire expression will be zero), and if x == -y then the second factor will be zero, so it basically functions like an or

    This answer was originally posted on StarkNet Discord

    Newton

    answered

    5 months ago

    Your answer

    NEWTON

    NEWTON