Why the double "=" in if statement (if @P == 2)

   3269   8   0
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Hi!

I always wondered why we need to use two “=” (or &) in an if statement but not in other situations. Like here:

if (@uv.x == 0 && @uv.y == 0)

-Olivier
Edited by olivierth - Sept. 19, 2018 11:54:13
User Avatar
Member
471 posts
Joined: July 2005
Offline
Hi,

it is just because “=” is the assignment operator, which is used to assign values to variables. “==” on the other hand is the equality operator, which is like a binary function with a boolean result, to compare two values. It can be very dangerous/confusing mixing them up.

Attachments:
operators.hipnc (72.0 KB)

User Avatar
Member
2035 posts
Joined: Sept. 2015
Offline
What other situations do you mean where you don't have to use:

two “=” (or &) in an if statement

Single equal symbol is an assignment operation; Double equal symbols is a comparing operation.

Maybe there's some situations where the compare is only a single equal symbol? Perhaps there's some older expression contexts that allow single equal symbol to be used as a comparative operator? I think I may have seen that, if this is what your referring to.

Houdini can have different contexts for using ‘code’, and usually there are some variations in the syntax ‘requirements/limitations’.
User Avatar
Member
7733 posts
Joined: Sept. 2011
Offline
Group syntax accepts either form for comparisons. Because assignments don't make sense in this context, it can be assumed that the symbol is always refers to a comparison for terseness.
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Thanks for the explanations!

I see a lot of people using different symbols in “if” statements that I've never used. I wish there was a list of the symbols useful in “if” statements with explanations.

-Olivier
User Avatar
Member
359 posts
Joined: April 2017
Offline
http://www.sidefx.com/docs/houdini/vex/lang.html#operators [www.sidefx.com]
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
7733 posts
Joined: Sept. 2011
Offline
olivierth
Thanks for the explanations!

I see a lot of people using different symbols in “if” statements that I've never used. I wish there was a list of the symbols useful in “if” statements with explanations.

-Olivier

Which language, hscript or python or VEX?
User Avatar
Staff
5156 posts
Joined: July 2005
Offline
In C++, you've got logical operations and bitwise operations. Logical operations assume that when comparing two numbers, True is non-zero and False is zero. Bitwise operations operate per bit, or'ing or and'ing each bit against the corresponding bit in the other value. So (12 && 5) is True, while (12 & 5) is 4 (12 is 1100, 5 is 0101 and 4 is 0100). Most of the time you'll be using logical operations ( && || ^^, and, or, exclusive or) and not bitwise ones ( & | ^ ).
User Avatar
Member
1004 posts
Joined: April 2017
Offline
I'm talking about Vex.


Thanks toadstorm, that's very helpful!

-Olivier
  • Quick Links