& vs && — how can the first case be used?

mnero

New Member
\[quote\] (a > b) & (c < d), the components are evaluated left to right, so (a > b) is evaluated first. If (a > b) is false, the entire expression is false regardless of the result of the component (r < d). Nevertheless, the component (c < d) will still be evaluated. However, in the expression (a > b) && (c < d), the component (c < d) will not be evaluated if (a > b) evaluates to false. This is known as short circuiting.\[/quote\]Came across this paragraph in a Java book. I have been programming in various languages before, but I've never found a need for '&'. Why would one want to evaluate the second statement if it's known that the end result is not affected by it? Is there any use for it; does it come due to historical reasons?Same question applies to | and || as well.
 
Top