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 moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Short-Circuit Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Short-Circuit Problem" Watch "Short-Circuit Problem" New topic

Short-Circuit Problem

Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344

Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
||(short circuit OR) don't bother to check the second OR if the first one is true while (|) bitwize OR does.

~Sanjeev Singh<br />SCJP 1.5
annapurna madala

Joined: Oct 30, 2006
Posts: 6
As you said thats the short-circuit problem
In the first case, ++z>5 evaluates to true, so the ++z>6 will not be evaluated(because '||' is a short-circuit operator)
where as in the second case, even when the first operand evaluates to true ++z>6 will be executed giving the output as 8
Have you checked out Aspose?
subject: Short-Circuit Problem
It's not a secret anymore!