Java Reference
In-Depth Information
Often the and or or is clearly stated, and then it isn't too hard to implement it.
Sometimes, though, the wording isn't as explicit. It is quite common that the
individual conditions are nicely set apart in a bulleted list, but with little
indication of how they should be combined. The instructions for the 1992 tax
return say that you can claim single filing status if any one of the following is
true:
ȗ
You were never married.
ȗ
You were legally separated or divorced on December 31, 1992.
ȗ
You were widowed before January 1, 1992, and did not remarry in 1992.
Because the test passes if any one of the conditions is true, you must combine
the conditions with or. Elsewhere, the same instructions state that you may use
the more advantageous status of married filing jointly if all five of the following
conditions are true:
ȗ
Your spouse died in 1990 or 1991 and you did not remarry in 1992.
ȗ
You have a child whom you can claim as dependent.
ȗ
That child lived in your home for all of 1992.
ȗ
You paid over half the cost of keeping up your home for this child.
ȗ
You filed (or could have filed) a joint return with your spouse the year he
or she died.
Because all of the conditions must be true for the test to pass, you must combine
them with an and.
A DVANCED T OPIC 5.4: Lazy Evaluation of Boolean
Operators
The && and || operators in Java are computed using lazy (or short circuit)
evaluation. In other words, logical expressions are evaluated from left to right,
and evaluation stops as soon as the truth value is determined. When an and is
evaluated and the first condition is false, then the second condition is skippedȌ
208
Search WWH ::




Custom Search