I have a questions regarding the chained comparisons in Julia. I read this section in the manual but it is still unclear.
In Julia, does this:
if var1 && var2 != 1
mean this (in Python):
if (var1 and var2) != 1:
Thank you!
I have a questions regarding the chained comparisons in Julia. I read this section in the manual but it is still unclear.
In Julia, does this:
if var1 && var2 != 1
mean this (in Python):
if (var1 and var2) != 1:
Thank you!
From what I could read on that page and a linked page (http://docs.julialang.org/en/latest/manual/control-flow/#man-short-circuit-evaluation), no. The order of operations is different. It ends up like this:
First, the xscalar variable gets checked for a value that would satisfy an if statement, as if you did
Then, if, and only if that is accepted, does the next part get evaluated:
In other words, these two statements are roughly equivalent:
(forgive the lack of julia syntax knowledge)
A python equivalent of this would be:
or, with parentheses to show with more clarity,