Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using switch for long decision chains
#1
Although there is no limit to the number of if... else decisions you can chain together, both PHP and ActionScript offer an alternative approach through the use of switch statements. This method is more efficient when a large number of alternatives are involved, because thecondition is tested only once, whereas it’s tested each time in an elseif statement.  switch statements are also often easier to read. The PHP script for the multiconverter you’ll build in this chapter (yes, you’re nearly there) handles more than 20 choices, so it’s an ideal candidate for switch.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)