This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
the result is true, false, false the part i don't understand is that the '&&' operator has a higher priority over '||' therfore it'll be evaluated first, but this is not what is happening. for a strange reason '||' is evaluated first. any ideas why?
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
hi: boolean x = (a = true) || (b = true) && (c = true); this statement is equilvalent to: boolean x = (a = true) || ((b = true)) && (c = true)); In short ciruit operator OR, if the left side is true, the right side is not evaluated. In the previouse statement <a=true> then the right statement will never be evaluated, and b & c will stay false.
SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
My understanding: operator precedene does not directly dictate order of evaluation - it dictates how operands get associated with operators. Evaluation proceeds from left to right. So as mentioned above a + b * c is treated as: a + (b * c) and evaluation goes from left to right as opposed to: (b * c) + a You can convince yourself of this with:
The Inner that is named is not the true Inner.
Joined: Jul 21, 2003
you are probably right Steve, however operator evaluation order sometimes gets really uncomfortable. there is a lot of question regarding this matter in 'Dan Chisholm' exams, for instance...
this is evaluated as: a=(int)((1)+(++a + a++)) Steve, what do you think about this: to evaluate an expression: 1) Use brackets to seperate operators with higher priorities. 2) always start evaluating from left to right. for example: a = a + b * c; 1) a = a + (b * c) 2) start evaluating from L --> R
Joined: Sep 03, 2003
I think that is exactly what compilers are supposed to be doing. HOWEVER, quoting from Kernighan & Ritchie "...writing code that depends on order of evaluation is a bad programming practive in any language." HOWEVER, I believe Java specifies left-to-right order more rigorously than the C specification does: evaluation order
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com