• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Controlling Your Code I: Testing > Making Multiple Decisions

Making Multiple Decisions

The problem with if()…else is that normally you can make only a single decision. The statement calculates a single logical result and performs one of two actions. However, plenty of situations require multiple decisions before you can decide which action to take.

For example, the pre-tax price calculation from Listings 6.1 and 6.2 probably should test not only that the input tax_rate is greater than or equal to 0, but also that it's less than 1. (This means that the rate is below 100%, which is a reasonable restriction in the real world.) The next few sections show you three solutions to this kind of problem.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint