0

I wanted to ask if is it available to use OR operator in IF conditions, because its giving me awkward results, like this:

contract test {
  if(player1Points > Player2Points || player1Points >= 50){
      result = 1;
  }
}

any help ??

1
  • "giving me awkward results" - what awkward results??? And why have you posted a code that doesn't even compile??? – goodvibration Jul 7 '19 at 11:26
2

Yes, you can use it.

From the docs:

The operators || and && apply the common short-circuiting rules. This means that in the expression f(x) || g(y), if f(x) evaluates to true, g(y) will not be evaluated even if it may have side-effects.

Try with this code:

pragma solidity ^0.5.0;

contract Test {

    function comparePoints (uint player1Points, uint player2Points) public pure returns (uint) {
        uint result;

        if(player1Points > player2Points || player1Points >= 50){
            result = 1;
        }
        return result;
    }
}

Maybe the following sections will be useful to start writing smart contracts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.