hi guys, one thing that i curious about `and` `&am...
# getting-started
c
hi guys, one thing that i curious about
and
&&
for example:
Copy code
val a = 3
        val b = 4
        val c = 5
        val d = 3

        val result1 = b == c && a == d

        val result2 = (b == c) and (a == d)
1) the result2 if we write
val result2 = b == c and a == d
will not work. not sure why 2) For result1 because the b==c is false. so will not run a==d case. but result2 will get false false so finally will be false. which means result1 only perform one time check and result2 perform 2 times check. Is my understanding correct?
k
1) operator precedence, which is a big disadvantage of infix functions in general. That expression without parentheses is interpreted as
((b == c) and a) == d
.
2) Yes, that's correct.
c
hmmm got it. then what's the benefit we using
and
or
🤔
k
For booleans nothing (except maybe if you want the right hand side side effect but that's pretty obscure); but they're mainly the bitwise operators for intergers.
👍 1
c
oh, i understand. Thanks very much for your great explanation.