What is the difference between
if 0 = value1 then...
and
if value1 = 0 then...
I see some people do it the first method. I wonder if there is any advantages?
What is the difference between 0 = value1
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
- Marina Pashkova
- Posts: 2758
- Joined: 27 Jul 2007
-
- Posts: 43
- Joined: 01 Dec 2008
- Has thanked: 2 times
- Been thanked: 2 times
TJ: there is no difference in the result; the reason some programmers do this is that in some languages you can avoid some programmer errors by doing your comparisons this way.
In 'C' language it is a common error to code "if x = 0" (an assignment of value: assigns 0 and the 'if' will always be false) instead of the desired "if x==0" (a comparison). This error code will compile and execute but introduces a hard-to-find bug. However if you make the same equal-sign error by coding "if 0 = x" then the compiler will complain. Hope that was clear. I don't see an advantage in EL, unless you are used to looking at your comparisons in this format.
In 'C' language it is a common error to code "if x = 0" (an assignment of value: assigns 0 and the 'if' will always be false) instead of the desired "if x==0" (a comparison). This error code will compile and execute but introduces a hard-to-find bug. However if you make the same equal-sign error by coding "if 0 = x" then the compiler will complain. Hope that was clear. I don't see an advantage in EL, unless you are used to looking at your comparisons in this format.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times