Java Reference
In-Depth Information
switch statements in the Sun C compiler front end. Of the 244 switch
statements, each of which had an average of 7 cases, only 3 percent used the
fall-through behavior. That is, the defaultȌfalling through to the next case
unless stopped by a break Ȍwas wrong 97 percent of the time. Forgetting to
type the break is an exceedingly common error, yielding incorrect code.
We leave it to you to decide whether or not to use the switch statement. At any
rate, you need to have a reading knowledge of switch in case you find it in the
code of other programmers.
5.3.2 Nested Branches
Some computations have multiple levels of decision making. You first make one
decision, and each of the outcomes leads to another decision. Here is a typical
example.
In the United States, taxpayers pay federal income tax at different rates depending
on their incomes and marital status. There are two main tax schedules: one for
single taxpayers and one for married taxpayers Ȓfiling jointlyȓ, meaning that the
married taxpayers add their incomes together and pay taxes on the total. (In fact,
there are two other schedules, Ȓhead of householdȓ and Ȓmarried filing separatelyȓ,
which we will ignore for simplicity.) Table 1 gives the tax rate computations for
each of the filing categories, using the values for the 1992 federal tax return. (We're
using the 1992 tax rate schedule in this illustration because of its simplicity.
Legislation in 1993 increased the number of rates in each status and added more
complicated rules. By the time that you read this, the tax laws may well have
become even more complex.)
198
199
Table 1 Federal Tax Rate Schedule (1992)
If your filing status is Single:
If your filing status is Married:
Tax Bracket
Percentage
Tax Bracket
Percentage
$0 Ȟ $21,450
15%
$0 Ȟ $35,800
15%
Amount over $21,450, up
to $51,900
28%
Amount over $35,800, up
to $86,500
28%
Amount over $51,900
31%
Amount over $86,500
31%
Search WWH ::




Custom Search