-3

So I came across the following syntax for a coding-game solution:

.
.
n and 9

and I didn't knew how to interpret it, thus I tried

2 and 3 #3
3 and 2 #2
.

Why does x and y (seems to) equal y i.e how is this calculated/understood?

CutePoison
  • 4,679
  • 5
  • 28
  • 63
  • Yeah, the docs explain it; "The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned." Just didn't knew how it returned stuff that wasn't boolean when using AND – CutePoison Feb 10 '22 at 14:10

2 Answers2

0

This is called short-circuiting in boolean expressions if the first is true(non zero considered as true) it goes to 2nd if this was or if the first was false(0 is considered false) it goes to 2nd try it or as or integers hope this clears stuff up

Ahmed Ali
  • 257
  • 1
  • 7
-1

Chain of logical operators returns the first (counting from left-most value) item that lets you know the logical value of the whole statement. So, in case of and, there are 2 options - one of the values is False, at which point you know that whole statement is False and you return that value without checking anything further on the right, or all of them are True and you return the last one, as only then you know that it will be True.

matszwecja
  • 6,357
  • 2
  • 10
  • 17